Skip to content

Commit dfddcc9

Browse files
zoontekmeta-codesync[bot]
authored andcommitted
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: #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: #56413 (comment) Reviewed By: cipolleschi Differential Revision: D100384656 Pulled By: alanleedev fbshipit-source-id: 570323408c788d58d1249671a2b19c8539815d00
1 parent 40c7d8f commit dfddcc9

File tree

1 file changed

+26
-12
lines changed
  • packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view

1 file changed

+26
-12
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/WindowUtil.kt

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,23 +106,37 @@ private fun Window.statusBarShow() {
106106
internal fun Window.enableEdgeToEdge() {
107107
WindowCompat.setDecorFitsSystemWindows(this, false)
108108

109+
val insetsController = WindowInsetsControllerCompat(this, decorView)
109110
val isDarkMode = UiModeUtils.isDarkMode(context)
110111

112+
statusBarColor = Color.TRANSPARENT
113+
111114
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
115+
navigationBarColor = Color.TRANSPARENT
116+
117+
val attributes = intArrayOf(android.R.attr.enforceNavigationBarContrast)
118+
val typedArray = context.theme.obtainStyledAttributes(attributes)
119+
120+
val enforceNavigationBarContrast =
121+
try {
122+
typedArray.getBoolean(0, true)
123+
} finally {
124+
typedArray.recycle()
125+
}
126+
112127
isStatusBarContrastEnforced = false
113-
isNavigationBarContrastEnforced = true
114-
}
128+
isNavigationBarContrastEnforced = enforceNavigationBarContrast
115129

116-
statusBarColor = Color.TRANSPARENT
117-
navigationBarColor =
118-
when {
119-
Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q -> Color.TRANSPARENT
120-
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !isDarkMode -> LightNavigationBarColor
121-
else -> DarkNavigationBarColor
122-
}
123-
124-
WindowInsetsControllerCompat(this, decorView).run {
125-
isAppearanceLightNavigationBars = !isDarkMode
130+
if (enforceNavigationBarContrast) {
131+
insetsController.isAppearanceLightNavigationBars = !isDarkMode
132+
}
133+
} else {
134+
val isAppearanceLightNavigationBars =
135+
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !isDarkMode
136+
137+
navigationBarColor =
138+
if (isAppearanceLightNavigationBars) LightNavigationBarColor else DarkNavigationBarColor
139+
insetsController.isAppearanceLightNavigationBars = isAppearanceLightNavigationBars
126140
}
127141

128142
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {

0 commit comments

Comments
 (0)