[expo-screen-orientation] Screen orientation does not lock or trigger with EAS Build
Problem
Summary On a built app with EAS build, calling https://docs.expo.dev/versions/latest/sdk/screen-orientation/#screenorientationlockasyncorientationlock does not trigger the screen to rotate and lock on iOS. When the app isn't built with EAS build, and created with expo build, the screen orientation lock async function works. Could possibly be related to: https://github.com/expo/expo/issues/11558 Managed or bare workflow? If you have `ios/` or `android/` directories in your project, the answer is bare! managed What platform(s) does this occur on? iOS SDK Version (managed workflow only) 43 Environment Expo CLI 4.12.10 environment info: System: OS: macOS 11.6 Shell: 5.8 - /bin/zsh Binaries: Node: 14.15.1 - ~/.nvm/versions/node/v14.15.1/bin/node Yarn: 3.0.2 - ~/.nvm/versions/node/v14.15.1/bin/yarn npm: 6.14.8 - ~/.nvm/versions/node/v14.15.1/bin/npm Watchman: 2021.06.07.00 - /usr/local/bin/watchman Managers: CocoaPods: 1.11.2 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4 Android SDK: API Levels: 30, 31 Build Tools: 29.0.2, 30.0.2, 31.0.0 System Images: android-30 | Google APIs Intel x86 Atom, android-30 | Google Play Intel x86 Atom, android-31 | Android TV Intel x86 Atom, android-31 | ARM 64 v8a, android-31 | Intel x86 Atom_64, android-31 | Google TV Intel x86 Atom, android-31 | Google APIs ARM 64 v8a, androi
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Fix Screen Orientation Lock Issue in EAS Build for iOS
The issue arises because the Expo SDK version 43 has a known bug related to screen orientation locking when using EAS Build. This bug prevents the screen orientation from being locked or changed as expected on iOS devices. The underlying cause is likely related to the way EAS Build handles native modules compared to the classic build process.
Awaiting Verification
Be the first to verify this fix
- 1
Update Expo SDK Version
Upgrade your Expo SDK to the latest stable version to ensure compatibility and bug fixes. This may resolve the issue with screen orientation locking.
bashexpo upgrade - 2
Check EAS Build Configuration
Ensure that your EAS Build configuration is correctly set up. Verify that the `eas.json` file includes the correct build profiles for iOS.
bashcat eas.json - 3
Implement Orientation Lock Workaround
If the issue persists after upgrading, implement a workaround by manually setting the orientation lock in the app's entry point using the ScreenOrientation API.
typescriptimport * as ScreenOrientation from 'expo-screen-orientation'; async function lockOrientation() { await ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.PORTRAIT); } lockOrientation(); - 4
Test on Physical Device
Deploy the updated app to a physical iOS device to test if the screen orientation locking works as expected. Ensure that you test both portrait and landscape orientations.
basheas build --platform ios - 5
Monitor for Errors
After deploying, monitor the app for any errors related to screen orientation. Check the console logs for any warnings or errors that may indicate further issues.
bashexpo start --no-dev --minify
Validation
Confirm that the screen orientation locks correctly when the lock function is called. Test both portrait and landscape modes to ensure the functionality works as intended on a physical device.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep