'React native: lock screenOrientation on IOS phone
I'm stumped on something you guys may have encountered as well. I've tried to find a way to handle this without any success. Every lead I found did not match my simple needs.
Here's my problem. I'm using react-navigation (expo + VScode + Windows) to navigate from one screen to another, and I have to change the screen orientation from portrait to landscape and the reverse way around.
It works perfectly on android, just by using the options (see below)
<Stack.Screen
name={MainFlowKeys.Home}
component={Home}
options={{ orientation: "portrait_up" }}
/>
but this DOESN'T work on IOS. I use a physical device for testing it (iphone SE).
So I've tried to use an expo module (screen-orientation), but it's buggy (the screen is rotated when loaded but then the user can rotate it back afterward, it's not LOCKED).
I'm using this function:
export const forceLandscape = async () => {
await ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.LANDSCAPE_RIGHT);
};
It's trigerred in each page with:
useEffect(() => {
if (Platform.OS === "ios") forcePortrait();
}, []);
but it doesn't work as well (I mean the screen rotates but the user can rotates it back afterward, it's NOT locked)
Did you guys got the same problem and how did you solve it ? What is it I am missing ?
Thanks by advance for your help.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|