react-native-orientation-locker
react-native-orientation-locker copied to clipboard
IOS Issue
Hello !
I have an issue with IOS, the screen doesn't lock. It just rotation on an Orientation.lockToLandscape() but it go back to the original device orientation just after.
import Orientation from 'react-native-orientation-locker'
const Settings = () => {
const labels = useSelector((state) => state.labels.list)
const dispatch = useDispatch()
const navigation = useNavigation()
useEffect(() => {
function _onOrientationDidChange(orientation) {
if (orientation == 'PORTRAIT') {
Orientation.lockToLandscapeLeft()
}
console.log(orientation)
}
Orientation.lockToLandscapeLeft()
Orientation.addOrientationListener(_onOrientationDidChange)
//cleanup optional code
return () => {
Orientation.lockToPortrait()
Orientation.removeOrientationListener(_onOrientationDidChange)
}
})
I had the same behaviour. Then I found out that the changes in the AppDelegate were missing (see chapter configuration in the readme). In our case, the AppDelegate is written in Swift. After the following addition, it worked as expected:
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return Orientation.getOrientation()
}
same issue
I have same issue.
Be sure to place this function before the last "end"
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return [Orientation getOrientation];
}
Even with that included, it is not working on iOS for me. Specifically, it is not working when included within a useEffect
block - it works outside of them.
It looks like this merge should fix the issue, but hasn't been released yet. https://github.com/wonday/react-native-orientation-locker/pull/225