react-native(리액트 네이티브) API - OrientationChange
const React = require('react')
const ReactNative = require('react-native')
const {DeviceEventEmitter, Text, View} = ReactNative
export default class OrientationChangeExample extends React.Component {
state = {
currentOrientation: '',
orientationDegrees: 0,
inLandscape: false,
}
componentDidMount() {
this._orientationSubscription = DeviceEventEmitter.addListener(
'namedOrientationDidChange',
this._onOrientationChange,
)
}
componentWillUnmount() {
this._orientationSubscription.remove()
}
_onOrientationChange = orientation => {
this.setState({
currentOrientation: orientation.name,
orientationDegrees: orientation.ratationDegrees,
isLandscape: orientation.isLandscape,
})
}
render() {
return(
<View>
<Text>
OrientationChangeExample | listening to orientation changes
</Text>
<Text>{JSON.stringify(this.state)}</Text>
</View>
)
}
}
exports.title = 'OrientationChangeExample'
exports.description = 'listening to orientation changes'
exports.examples = [
{
title: 'OrientationChangeExample',
description: 'listening to device orientation changes',
render() {
return <OrientationChangeExample />
},
},
]
'프로그래밍(Programming) > 리액트 네이티브(React Native)' 카테고리의 다른 글
react-native(리액트 네이티브) API - PermissionsAndroid (0) | 2019.01.07 |
---|---|
react-native(리액트 네이티브) API - PanResponder (0) | 2019.01.07 |
react-native(리액트 네이티브) API - Linking (0) | 2019.01.07 |
react-native(리액트 네이티브) API - LayoutFlexbox (0) | 2019.01.07 |
react-native(리액트 네이티브) API - LayoutEvent (0) | 2019.01.07 |