@@ -28,15 +28,6 @@ internal val LightNavigationBarColor = Color.argb(0xe6, 0xFF, 0xFF, 0xFF)
2828// https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/res/remote_color_resources_res/values/colors.xml;l=67
2929internal val DarkNavigationBarColor = Color .argb(0x80 , 0x1b , 0x1b , 0x1b )
3030
31- /* *
32- * Whether edge-to-edge is enforced. Computed once in [initEdgeToEdge], based on:
33- * - The edge-to-edge feature flag has been explicitly enabled
34- * - The device is running Android 16+ with targetSdk 35+ (where edge-to-edge is always enforced)
35- * - The device is running Android 15 with targetSdk 35+ without opting out
36- */
37- internal var isDeviceRunningEdgeToEdge: Boolean = false
38- private set
39-
4031/* *
4132 * This does not enable or apply edge-to-edge behavior, it simply tracks whether it has been flagged
4233 * as enabled elsewhere in the application.
@@ -49,23 +40,27 @@ public fun setEdgeToEdgeFeatureFlagOn() {
4940}
5041
5142internal fun initEdgeToEdge (activity : Activity ) {
52- isDeviceRunningEdgeToEdge =
53- when {
54- ! AndroidVersion .isAtLeastTargetSdk35(activity) -> isEdgeToEdgeFeatureFlagOn
55- Build .VERSION .SDK_INT >= AndroidVersion .VERSION_CODE_BAKLAVA -> true
56- else -> {
57- val attributes = intArrayOf(AndroidVersion .ATTR_WINDOW_OPT_OUT_EDGE_TO_EDGE_ENFORCEMENT )
58- val typedArray = activity.theme.obtainStyledAttributes(attributes)
59-
43+ // When the app targets SDK 35+, edge-to-edge may be enforced by the OS even if the
44+ // feature flag wasn't explicitly set. In that case, turn the flag on to match.
45+ if (AndroidVersion .isAtLeastTargetSdk35(activity)) {
46+ if (Build .VERSION .SDK_INT >= AndroidVersion .VERSION_CODE_BAKLAVA ) {
47+ // The device is running Android 16+ (where edge-to-edge is always enforced)
48+ isEdgeToEdgeFeatureFlagOn = true
49+ } else {
50+ val attributes = intArrayOf(AndroidVersion .ATTR_WINDOW_OPT_OUT_EDGE_TO_EDGE_ENFORCEMENT )
51+ val typedArray = activity.theme.obtainStyledAttributes(attributes)
52+
53+ // The device is running Android 15 with / without opting out
54+ isEdgeToEdgeFeatureFlagOn =
6055 try {
6156 ! typedArray.getBoolean(0 , false )
6257 } finally {
6358 typedArray.recycle()
6459 }
65- }
66- }
60+ }
61+ }
6762
68- if (isDeviceRunningEdgeToEdge ) {
63+ if (isEdgeToEdgeFeatureFlagOn ) {
6964 activity.window.enableEdgeToEdge()
7065 }
7166}
@@ -100,7 +95,7 @@ internal fun Window.setStatusBarVisibility(isHidden: Boolean) {
10095
10196@Suppress(" DEPRECATION" )
10297private fun Window.statusBarHide () {
103- if (isDeviceRunningEdgeToEdge ) {
98+ if (isEdgeToEdgeFeatureFlagOn ) {
10499 WindowInsetsControllerCompat (this , decorView).run {
105100 systemBarsBehavior = WindowInsetsControllerCompat .BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
106101 hide(WindowInsetsCompat .Type .statusBars())
@@ -119,7 +114,7 @@ private fun Window.statusBarHide() {
119114
120115@Suppress(" DEPRECATION" )
121116private fun Window.statusBarShow () {
122- if (isDeviceRunningEdgeToEdge ) {
117+ if (isEdgeToEdgeFeatureFlagOn ) {
123118 WindowInsetsControllerCompat (this , decorView).run {
124119 systemBarsBehavior = WindowInsetsControllerCompat .BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
125120 show(WindowInsetsCompat .Type .statusBars())
0 commit comments