Expo Screen Orientation, How To Force Certain Orientation?

Please provide the following:

  1. SDK Version: 39.0
  2. Platforms(Android/iOS/web/all): iOS (All?)

I’m using expo’s screen orientation module to try and control the orientation of my application. The problem I’m facing is that ScreenOrientation does not provide a way to actually rotate the application to the desired orientation without having the user also rotate the device, instead .lockAsync only makes the orientation stay locked at the given orientation if the user rotates the device to that orientation in the first place:

ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.PORTRAIT_UP);

If the orientation is already set to landscape, the above code will not rotate the orientation to portrait up on iOS. Instead, it only locks the orientation to portrait up if the user rotates the device to portrait up first. If the user does not rotate the device, the orientation stays in landscape. How do I force the application to change to the given orientation without requiring the user to first rotate their device that way? Is the only way to have the user rotate the device to that orientation?

Hey @iway1,

The screen should reorient. Can you provide me with a reproducible example of this I can test on my end? I just created a Snack and it seems to be working as expected. https://snack.expo.io/@adamjnav/46c554 (Tested with PORTRAIT_UP and LANDSCAPE)

Cheers,
Adam

1 Like

I attempted to recreate it and it works except when I call it while a Modal is visible. Not sure if that is intended or not. If I call ScreenOrientation.lockAsync while a modal is open, it does not rotate the modal nor does it rotate the screen that the modal is covering, instead it does what I described above. That solves my problem though, I will just have to create a custom modal component instead of the built in react native modal and the screen should rotate like I want.

Is it intended that ScreenOrientation.lockAsync does not rotate a screen while a modal is open?

Thanks you!