Skip to content

Instantly share code, notes, and snippets.

@Ranatchai
Last active November 12, 2018 21:51
Show Gist options
  • Save Ranatchai/90f1a29771ec1f361f8e0a489282d5eb to your computer and use it in GitHub Desktop.
Save Ranatchai/90f1a29771ec1f361f8e0a489282d5eb to your computer and use it in GitHub Desktop.
React Native Orientation Listener
function onOrientationChange(callback) {
Dimensions.addEventListener('change', () => {
const { width, height } = Dimensions.get('window')
const orientation = width > height ? 'landscape': 'portrait'
callback(orientation)
})
}
onOrientationChange((orientation) => {
this.setState({ orientation })
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment