Reputation: 749
I want to lock the orientation of the first screen of the app to portrait. In some screens, I need landscape orientation. I am using the react-native-orientation plugin. But when I launch the application, I see landscape orientation for a while and then quickly rotating to portrait orientation. The next screens are ok.
Here is my code:
componentDidMount() {
Orientation.lockToPortrait();
}
Is it possible to solve this performance issue?
Upvotes: 1
Views: 1345
Reputation: 749
It was my error. I used in one class redundant code:
const setLandscapeRightOrientation = Platform.select({
ios: Orientation.lockToLandscapeRight(),
android: Orientation.lockToLandscapeLeft(),
});
Upvotes: 0
Reputation: 2870
Add below code in your page where orientation lock is delayed:
componentWillMount(){
Orientation.lockToPortrait();
Orientation.addOrientationListener(this._orientationDidChange);
}
_orientationDidChange(orientation) {
Orientation.lockToPortrait();
}
componentWillUnmount() {
// remove listener
Orientation.removeOrientationListener(this._orientationDidChange);
}
Upvotes: 1
Reputation: 3475
react-native-orientation no longer seems maintained.
I encourage you to use react-native-orientation-locker which also provides Orientation.lockToPortrait()
Upvotes: 0