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 />
},
},
]


+ Recent posts