react-native-orientation-locker
react-native-orientation-locker copied to clipboard
Crashes on iOS when calling Orientation.lockToLandscapeLeft
I may be using this wrong, but the only way I have gotten RN to re-render when orientation changes is to call lockToXXX
when the device orientation changes.
Here's some code:
private onOrientationDidChange = (orientation: OrientationType) => {
if (orientation === 'PORTRAIT') {
Orientation.lockToPortrait();
} else if (orientation === 'LANDSCAPE-LEFT') {
Orientation.lockToLandscapeLeft();
} else {
Orientation.lockToLandscapeRight();
}
setTimeout(() => {
this.setState({ orientation });
}, 100);
};
This is in an HoC I wrote so the we can selectively add orientation behaviors to components in our app.
This works fine on Android.
The hacky setState
in a timeout seems to be necessary in order for the wrapped component to render after the orientation change has completed and get the correct dimensions for resizing the layout.
The issue is that on iOS, the app crashes when I call Orientation.lockToLandscapeLeft()
.
I've stepped through in the native code and it crashes on line 286 of Orientation.m:
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationLandscapeRight] forKey:@"orientation"];
I'm not an iOS dev, so debugging in XCode is a little unfamiliar to me -- it doesn't seem to be generating a readable stack trace or giving any error message -- I'm probably looking in the wrong place.
Any feedback or thoughts as to what I'm doing wrong?
same. perhaps this is because in IOS i have already set it to orientation left?