Skip to content

Commit 0ffc42a

Browse files
vinceglbclaude
andcommitted
fix(mobile): Android navigation bar follows the app theme
React Native sets the navigation bar style once, at launch, from the system theme. When the app theme differs, Android draws the wrong contrast scrim behind a tappable navigation bar: a light band under the gesture handle in a dark app on an unfolded Galaxy Z Fold, or a dark one in a light app. Set it from themeAppearance, as StatusBar already does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 32ecd71 commit 0ffc42a

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

‎apps/mobile/modules/t3-native-controls/android/src/main/java/expo/modules/t3nativecontrols/T3NativeControlsModule.kt‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package expo.modules.t3nativecontrols
22

33
import android.content.Intent
4+
import android.os.Build
45
import android.text.format.DateFormat
56
import androidx.core.content.FileProvider
7+
import androidx.core.view.WindowCompat
68
import expo.modules.kotlin.Promise
9+
import expo.modules.kotlin.functions.Queues
710
import expo.modules.kotlin.modules.Module
811
import expo.modules.kotlin.modules.ModuleDefinition
912
import java.io.File
@@ -16,6 +19,15 @@ class T3NativeControlsModule : Module() {
1619
override fun definition() = ModuleDefinition {
1720
Name("T3NativeControls")
1821

22+
// React Native sets this once, at launch, from the system theme rather than the app's.
23+
AsyncFunction("setNavigationBarStyle") { light: Boolean ->
24+
// Below Android 10, React Native paints the navigation bar color itself.
25+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) return@AsyncFunction
26+
val window = appContext.currentActivity?.window ?: return@AsyncFunction
27+
val controller = WindowCompat.getInsetsController(window, window.decorView)
28+
controller.isAppearanceLightNavigationBars = light
29+
}.runOnQueue(Queues.MAIN)
30+
1931
Function("is24HourFormat") {
2032
val context = appContext.reactContext ?: error("The app is not active.")
2133
DateFormat.is24HourFormat(context)

‎apps/mobile/src/App.tsx‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import { installComposerAttachmentUploads } from "./state/composer-attachment-up
33
import { installThreadOutboxDelivery } from "./state/threadOutboxDelivery";
44
import * as Linking from "expo-linking";
55
import * as SplashScreen from "expo-splash-screen";
6+
import { requireNativeModule } from "expo";
67
import { useEffect } from "react";
7-
import { StatusBar } from "react-native";
8+
import { Platform, StatusBar } from "react-native";
89
import { GestureHandlerRootView } from "react-native-gesture-handler";
910
import { KeyboardProvider } from "react-native-keyboard-controller";
1011
import { SafeAreaProvider } from "react-native-safe-area-context";
@@ -222,6 +223,14 @@ function AppContent() {
222223
const { themeAppearance } = useAppearancePreferences();
223224
const navigationTheme = useMobileNavigationTheme();
224225

226+
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- matches the Android navigation bar to the app theme, as StatusBar does for the status bar
227+
useEffect(() => {
228+
if (Platform.OS !== "android") return;
229+
void requireNativeModule<{ setNavigationBarStyle(light: boolean): Promise<void> }>(
230+
"T3NativeControls",
231+
).setNavigationBarStyle(themeAppearance === "light");
232+
}, [themeAppearance]);
233+
225234
return (
226235
<>
227236
<SplashScreenCoordinator />

0 commit comments

Comments
 (0)