Last active
November 12, 2018 21:51
-
-
Save Ranatchai/90f1a29771ec1f361f8e0a489282d5eb to your computer and use it in GitHub Desktop.
React Native Orientation Listener
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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