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
This commit is contained in:
Mathieu Acthernoene authored and meta-codesync[bot] committed 2026-04-14 09:31:22 -07:00
1 parent 40c7d8f6f0
commit dfddcc9796
1 file changed
+27 -13
@@ -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) {