Skip to content

Instantly share code, notes, and snippets.

@janhesters
Created September 17, 2018 15:29
Show Gist options
  • Save janhesters/8807177d07b95fe3845b89d921134266 to your computer and use it in GitHub Desktop.
Save janhesters/8807177d07b95fe3845b89d921134266 to your computer and use it in GitHub Desktop.
// ... Other imports. Only import 'orientation' in the following line, if you are using TypeScript
import Orientation, { orientation } from 'react-native-orientation';
export default class App extends Component<Props> {
componentDidMount = () => {
Orientation.lockToPortrait();
Orientation.addOrientationListener(this.orientationDidChange);
};
componentWillUnmount = () => {
Orientation.removeOrientationListener(this.orientationDidChange);
};
// Again the type declaration 'orientation' is only for TypeScript
orientationDidChange = (orientation: orientation) => {
console.log(orientation);
};
render() {
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment