lock screen orientation only for phones, not tablets (maybe this is also about Expo Constants.statusBarHeight)

Please provide the following:

  1. SDK Version: 37
  2. Platforms(Android/iOS/web/all): Android/iOS

i want to allow users to use the app in landscape on a tablet, but only in portrait on a phone.

in app.json, i have "orientation": "portrait"

i installed expo-screen-orientation

i tried two different methods of implementing this and am getting the same problem with both versions:
I launch in landscape on iPhone and see the splash screen in landscape, then it switches to portrait as I’d hope for, but the status bar height offset (using expo constant) doesn’t work.

Version 1:

change app.json to "orientation": "default"

in App.js, I added:
!isWideScreen && ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.PORTRAIT_UP);

Version 2:

change app.json back to "orientation": "portrait"

in App.js, I added
isWideScreen && ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.DEFAULT);

I would expect Version 2 to behave exactly as the app did before messing with orientation at all on a phone, but i still get the statusbar height issue.

Any thoughts would be appreciated, also happy to provide more info if needed.

Edit: I just thought of a third way to do it, by keeping "orientation": "portrait" in app.json and changing the function in App.js to isWideScreen && ScreenOrientation.unlockAsync(); Will update with results.

Edit: This third version has the same issue. I’m stumped.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.