Handle edge-to-edge when it's not enabled by gradle property (#56055)

Summary:
On Android 15 (API 35), edge-to-edge is enforced by default unless the app explicitly opts out via `windowOptOutEdgeToEdgeEnforcement`. On Android 16+, it's always enforced regardless.

Previously, edge-to-edge behavior was only driven by the `edgeToEdgeEnabled` gradle property, meaning apps on Android 15+ could be in edge-to-edge mode without React Native being aware of it, leading to incorrect insets / layout behavior.

This PR introduces `isEdgeToEdge`, a computed value that accounts for the OS-level enforcement in addition to the gradle flag, and replaces most usages of `isEdgeToEdgeFeatureFlagOn` with it. A new `initEdgeToEdge(context, flag)` function replaces `setEdgeToEdgeFeatureFlagOn()` and reads the theme attribute to detect opt-out on API 35.

## Changelog:

[ANDROID] [FIXED] - Handle edge-to-edge when it's not enabled by the `edgeToEdgeEnabled` gradle property but enforced by the OS (Android 15+)

Pull Request resolved: https://github.com/facebook/react-native/pull/56055

Test Plan:
- Verify on Android 15 device/emulator **without** `edgeToEdgeEnabled = true`: `isEdgeToEdge` should be `true` (unless opted out via theme attribute).
- Verify on Android 16+ device/emulator: `isEdgeToEdge` should always be `true`.
- Verify on Android 14 and below without the flag: `isEdgeToEdge` should be `false`.
- Verify with `edgeToEdgeEnabled = true`: behavior unchanged, `isEdgeToEdge` is `true` on all API levels.

Reviewed By: javache

Differential Revision: D100437440

fbshipit-source-id: 7cc826ccd2d1596121671eb456358f558e14299c
This commit is contained in:
Mathieu Acthernoene authored and meta-codesync[bot] committed 2026-04-16 09:45:09 -07:00
1 parent a4f78b3d07
commit c2280e3201
3 files changed
+49 -6

No files matched your search

@@ -138,9 +138,7 @@ public class ReactActivityDelegate {
if (mActivity != null) {
Window window = mActivity.getWindow();
if (window != null) {
if (WindowUtilKt.isEdgeToEdgeFeatureFlagOn()) {
WindowUtilKt.enableEdgeToEdge(window);
}
WindowUtilKt.updateEdgeToEdgeFeatureFlag(mActivity);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && isWideColorGamutEnabled()) {
window.setColorMode(ActivityInfo.COLOR_MODE_WIDE_COLOR_GAMUT);
}
@@ -21,10 +21,27 @@ internal object AndroidVersion {
internal const val VERSION_CODE_VANILLA_ICE_CREAM: Int = 35
/**
* This is the version code for Android 16 (SDK Level 36). Delete it once we bump up the default
* compile SDK version to 36.
* This is the version code for Android 16 (SDK Level 36). Internally at Meta this code is also
* compiled against SDK 34, so we need to retain this constant instead of using
* [Build.VERSION_CODES.BAKLAVA] directly.
*/
private const val VERSION_CODE_BAKLAVA: Int = 36
internal const val VERSION_CODE_BAKLAVA: Int = 36
/**
* android.R.attr.windowOptOutEdgeToEdgeEnforcement added in API 35. Internally at Meta this code
* is compiled against an SDK that may not have this attribute defined.
* https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/core/res/res/values/public-final.xml;l=3848
*/
internal const val ATTR_WINDOW_OPT_OUT_EDGE_TO_EDGE_ENFORCEMENT: Int = 0x0101069a
/**
* This method is used to check if the current device is running Android 15 (SDK Level 35) or
* higher and the app is targeting Android 15 (SDK Level 35) or higher.
*/
@JvmStatic
internal fun isAtLeastTargetSdk35(context: Context): Boolean =
Build.VERSION.SDK_INT >= VERSION_CODE_VANILLA_ICE_CREAM &&
context.applicationInfo.targetSdkVersion >= VERSION_CODE_VANILLA_ICE_CREAM
/**
* This method is used to check if the current device is running Android 16 (SDK Level 36) or
@@ -7,6 +7,7 @@
package com.facebook.react.views.view
import android.app.Activity
import android.graphics.Color
import android.os.Build
import android.view.Window
@@ -15,6 +16,7 @@ import androidx.core.view.ViewCompat
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
import com.facebook.react.util.AndroidVersion
import com.facebook.react.views.common.UiModeUtils
// The light scrim color used in the platform API 29+
@@ -37,6 +39,32 @@ public fun setEdgeToEdgeFeatureFlagOn() {
isEdgeToEdgeFeatureFlagOn = true
}
internal fun updateEdgeToEdgeFeatureFlag(activity: Activity) {
// When the app targets SDK 35+, edge-to-edge may be enforced by the OS even if the
// feature flag wasn't explicitly set. In that case, turn the flag on to match.
if (AndroidVersion.isAtLeastTargetSdk35(activity)) {
if (Build.VERSION.SDK_INT >= AndroidVersion.VERSION_CODE_BAKLAVA) {
// The device is running Android 16+ (where edge-to-edge is always enforced)
isEdgeToEdgeFeatureFlagOn = true
} else {
val attributes = intArrayOf(AndroidVersion.ATTR_WINDOW_OPT_OUT_EDGE_TO_EDGE_ENFORCEMENT)
val typedArray = activity.theme.obtainStyledAttributes(attributes)
// The device is running Android 15 with / without opting out
isEdgeToEdgeFeatureFlagOn =
try {
!typedArray.getBoolean(0, false)
} finally {
typedArray.recycle()
}
}
}
if (isEdgeToEdgeFeatureFlagOn) {
activity.window.enableEdgeToEdge()
}
}
@Suppress("DEPRECATION")
internal fun Window.setStatusBarTranslucency(isTranslucent: Boolean) {
// If the status bar is translucent hook into the window insets calculations