fix(mobile): respect Android device rotation lock instead of forcing rotation (#5403)
* release: v1.4.48-rc.0 [rc-slot:2026-06-05-15] * release: v0.0.1-rc.0 [rc-slot:2026-06-06-03] * fix(mobile): respect Android device rotation lock instead of forcing rotation The app rotated on Android even when the system auto-rotate lock was on. Expo's top-level `orientation: "default"` emits `android:screenOrientation="unspecified"`, which auto-rotates on many devices regardless of the lock, and the `react-native-screens` `orientation: 'all'` screenOption mapped to FULL_SENSOR, which forces rotation outright. react-native-screens exposes no orientation value that honors the rotation lock (even 'default' calls setRequestedOrientation(UNSPECIFIED) at runtime, overriding the manifest). The Android value that respects the lock is "fullUser", which must come from the manifest. So: - Add an `android-respect-rotation-lock` Expo config plugin that sets the main activity to `android:screenOrientation="fullUser"` (honors the lock; allows all orientations when unlocked, matching iOS). - Remove the runtime `orientation` screenOption so the manifest value governs. iOS behavior is unchanged (UISupportedInterfaceOrientations still lists all four). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
github-actions[bot]
parent
1d85515a3e
commit
26121a4315
@@ -78,6 +78,7 @@
|
||||
},
|
||||
"plugins": [
|
||||
"expo-router",
|
||||
"./plugins/android-respect-rotation-lock.js",
|
||||
[
|
||||
"expo-splash-screen",
|
||||
{
|
||||
|
||||
@@ -145,8 +145,12 @@ export default function RootLayout() {
|
||||
headerTintColor: colors.textPrimary,
|
||||
headerTitleStyle: { fontSize: 16, fontWeight: '600' },
|
||||
contentStyle: { backgroundColor: colors.bgBase },
|
||||
headerShadowVisible: false,
|
||||
orientation: 'all'
|
||||
headerShadowVisible: false
|
||||
// Why: deliberately no `orientation` screenOption. react-native-screens
|
||||
// has no value that respects the device rotation lock — even 'default'
|
||||
// calls setRequestedOrientation(UNSPECIFIED) at runtime, overriding the
|
||||
// manifest. Leaving it unset lets the manifest's "fullUser" (set by the
|
||||
// android-respect-rotation-lock config plugin) honor the auto-rotate lock.
|
||||
}}
|
||||
>
|
||||
<Stack.Screen
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
const { withAndroidManifest, AndroidConfig } = require('expo/config-plugins')
|
||||
|
||||
// Why: Expo's top-level `orientation` only emits portrait/landscape/unspecified.
|
||||
// "unspecified" still auto-rotates on many Android devices even when the system
|
||||
// rotation lock is on. "fullUser" honors the user's auto-rotate setting (no
|
||||
// rotation when locked) while still allowing every orientation when unlocked —
|
||||
// matching the iOS UISupportedInterfaceOrientations behavior. iOS is untouched.
|
||||
const ANDROID_SCREEN_ORIENTATION = 'fullUser'
|
||||
|
||||
module.exports = function withAndroidRespectRotationLock(config) {
|
||||
return withAndroidManifest(config, (cfg) => {
|
||||
const activity = AndroidConfig.Manifest.getMainActivityOrThrow(cfg.modResults)
|
||||
activity.$['android:screenOrientation'] = ANDROID_SCREEN_ORIENTATION
|
||||
return cfg
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user