react-native-orientation-locker
react-native-orientation-locker copied to clipboard
fix ios 16 Setting UIDevice.orientation
BUG IN CLIENT OF UIKIT: Setting UIDevice.orientation is not supported. Please use UIWindowScene.requestGeometryUpdate(_:)
#241
PS: Works on my end now, please update if you have any suggestions.
@ceddybi In my case, this change does not help, the screen orientation changes if I turn the phone.
This addresses the iOS 16 issue in our project, thanks for the fix!
@jfspencerAngel @ceddybi Before iOS 16, device orientation change notifies when locktolandscape or portrait but it is not working now(iOS 16) until rotate the device. something to do with setNeedsUpdateOfSupportedInterfaceOrientations ? https://developer.apple.com/documentation/uikit/uiviewcontroller/4047535-setneedsupdateofsupportedinterfa?language=objc
@ceddybi
Thank you for your PR
I suggest to apply below code, because UIDeviceOrientationDidChangeNotification
couldn't detect orientation change when orientation changed via lockTo**
method.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange:) name:UIApplicationWillChangeStatusBarOrientationNotification object:nil];
[self addListener:@"orientationDidChange"];
I know UIApplicationWillChangeStatusBarOrientationNotification
is deprecated from iOS13 but this library already used deprecated API like UIApplication.statusBarOrientation
, so I just suggest it. unfortunately I'm not a specialist of iOS dev🥲,
If you know any alternative solution, I hope you feel free to use that
useEffect(() => { Orientation.addLockListener(onOrientationDidChange); // ios16 can full screen when orientation lanspage // Orientation.addOrientationListener(onOrientationDidChange); // ios16 not full screen , only 1/2 screen
return (() => {
Orientation.removeOrientationListener(onOrientationDidChange);
})
}, [])