'expo screen orientation ios on navigation event
Expected: Screen orientation changes back to portrait on navigation event.
Actual: Screen orientation unchanged.
Works correctly on android but not on IOS. Changing the return statement of the useEffect can trigger a console.log from the navigation.removeListener. So the bug seems connected expo-screen-orientation.
Libraries:
- @react-navigation/native
- expo-screen-orientation
The code:
const navigation = useNavigation();
const lockToLandscape = React.useCallback(() => {
ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.LANDSCAPE);
}, []);
const lockToPortrait = React.useCallback(() => {
ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.PORTRAIT);
}, []);
React.useEffect(() => {
navigation.addListener(`focus`, lockToLandscape);
navigation.addListener(`blur`, lockToPortrait);
return () => {
navigation.removeListener(`blur`, lockToPortrait);
navigation.removeListener(`focus`, lockToPortrait);
}
}, [navigation, lockToPortrait, lockToLandscape]);
Questions:
- Is this a known bug that I'm unaware of?
- Where should i look for a fix?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
