From dfddcc97969fb4ea5728c2bcc965a8a6126d03ba Mon Sep 17 00:00:00 2001 From: Mathieu Acthernoene Date: Tue, 14 Apr 2026 09:31:22 -0700 Subject: [PATCH] Respect theme `enforceNavigationBarContrast` attribute (#56413) Summary: This PR adds respect of the theme's `enforceNavigationBarContrast` attribute in `WindowUtil` `enableEdgeToEdge` (this will allow us to delete our [EdgeToEdgePackage.kt](https://github.com/expo/expo/blob/main/packages/expo-modules-core/android/src/main/java/expo/modules/kotlin/edgeToEdge/EdgeToEdgePackage.kt) file, and prevent a glitch where the navigation bar is semi-opaque for a short instant when user explicitly set `android:enforceNavigationBarContrast` to `false`). ## Changelog: [ANDROID] [CHANGED] - Respect theme `enforceNavigationBarContrast` attribute Pull Request resolved: https://github.com/facebook/react-native/pull/56413 Test Plan: - Verified edge-to-edge rendering on API 30+ (transparent status/navigation bars, correct display cutout behavior). - Verified navigation bar contrast enforcement respects the theme attribute on API 29+ (with `android:enforceNavigationBarContrast` to `true` (default) and `false`). - Verified fallback navigation bar colors on API 26-28 (light/dark scrim) and API < 26 (dark scrim). Additional screenshots are found here: https://github.com/facebook/react-native/pull/56413#issuecomment-4242953634 Reviewed By: cipolleschi Differential Revision: D100384656 Pulled By: alanleedev fbshipit-source-id: 570323408c788d58d1249671a2b19c8539815d00 --- .../facebook/react/views/view/WindowUtil.kt | 40 +++++++++++++------ 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/WindowUtil.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/WindowUtil.kt index 0cff3bc458d..bac3acc79a7 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/WindowUtil.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/WindowUtil.kt @@ -106,23 +106,37 @@ private fun Window.statusBarShow() { internal fun Window.enableEdgeToEdge() { WindowCompat.setDecorFitsSystemWindows(this, false) + val insetsController = WindowInsetsControllerCompat(this, decorView) val isDarkMode = UiModeUtils.isDarkMode(context) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - isStatusBarContrastEnforced = false - isNavigationBarContrastEnforced = true - } - statusBarColor = Color.TRANSPARENT - navigationBarColor = - when { - Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q -> Color.TRANSPARENT - Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !isDarkMode -> LightNavigationBarColor - else -> DarkNavigationBarColor - } - WindowInsetsControllerCompat(this, decorView).run { - isAppearanceLightNavigationBars = !isDarkMode + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + navigationBarColor = Color.TRANSPARENT + + val attributes = intArrayOf(android.R.attr.enforceNavigationBarContrast) + val typedArray = context.theme.obtainStyledAttributes(attributes) + + val enforceNavigationBarContrast = + try { + typedArray.getBoolean(0, true) + } finally { + typedArray.recycle() + } + + isStatusBarContrastEnforced = false + isNavigationBarContrastEnforced = enforceNavigationBarContrast + + if (enforceNavigationBarContrast) { + insetsController.isAppearanceLightNavigationBars = !isDarkMode + } + } else { + val isAppearanceLightNavigationBars = + Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !isDarkMode + + navigationBarColor = + if (isAppearanceLightNavigationBars) LightNavigationBarColor else DarkNavigationBarColor + insetsController.isAppearanceLightNavigationBars = isAppearanceLightNavigationBars } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {