From 26121a4315e1809e82bbb39e1df3a558fd6e98b1 Mon Sep 17 00:00:00 2001 From: gsxdsm Date: Tue, 16 Jun 2026 04:45:58 +0800 Subject: [PATCH] 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) --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 (1M context) --- mobile/app.json | 1 + mobile/app/_layout.tsx | 8 ++++++-- mobile/plugins/android-respect-rotation-lock.js | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 mobile/plugins/android-respect-rotation-lock.js diff --git a/mobile/app.json b/mobile/app.json index 4f034020c..1381fc041 100644 --- a/mobile/app.json +++ b/mobile/app.json @@ -78,6 +78,7 @@ }, "plugins": [ "expo-router", + "./plugins/android-respect-rotation-lock.js", [ "expo-splash-screen", { diff --git a/mobile/app/_layout.tsx b/mobile/app/_layout.tsx index de1160c6b..4572790c9 100644 --- a/mobile/app/_layout.tsx +++ b/mobile/app/_layout.tsx @@ -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. }} > { + const activity = AndroidConfig.Manifest.getMainActivityOrThrow(cfg.modResults) + activity.$['android:screenOrientation'] = ANDROID_SCREEN_ORIENTATION + return cfg + }) +}