react-native-orientation-locker icon indicating copy to clipboard operation
react-native-orientation-locker copied to clipboard

IOS Issue

Open MagnasiePro opened this issue 3 years ago • 6 comments

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)
        }
    })

MagnasiePro avatar Nov 09 '21 11:11 MagnasiePro

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()
}

mactanner avatar Nov 25 '21 17:11 mactanner

same issue

GuilhermeSantosmain avatar Jan 05 '22 21:01 GuilhermeSantosmain

I have same issue.

mssoliveira avatar Sep 22 '22 14:09 mssoliveira

Be sure to place this function before the last "end"

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
  return [Orientation getOrientation];
}

amirbhz86 avatar Sep 24 '22 09:09 amirbhz86

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.

dinkel-dean avatar Nov 14 '22 14:11 dinkel-dean

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

dinkel-dean avatar Nov 14 '22 15:11 dinkel-dean