@@ -19,7 +19,9 @@ package com.google.samples.apps.nowinandroid
1919import android.os.Bundle
2020import android.util.Log
2121import androidx.activity.ComponentActivity
22+ import androidx.activity.SystemBarStyle
2223import androidx.activity.compose.setContent
24+ import androidx.activity.enableEdgeToEdge
2325import androidx.activity.viewModels
2426import androidx.compose.foundation.isSystemInDarkTheme
2527import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
@@ -31,13 +33,11 @@ import androidx.compose.runtime.getValue
3133import androidx.compose.runtime.mutableStateOf
3234import androidx.compose.runtime.setValue
3335import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
34- import androidx.core.view.WindowCompat
3536import androidx.lifecycle.Lifecycle
3637import androidx.lifecycle.lifecycleScope
3738import androidx.lifecycle.repeatOnLifecycle
3839import androidx.metrics.performance.JankStats
3940import androidx.profileinstaller.ProfileVerifier
40- import com.google.accompanist.systemuicontroller.rememberSystemUiController
4141import com.google.samples.apps.nowinandroid.MainActivityUiState.Loading
4242import com.google.samples.apps.nowinandroid.MainActivityUiState.Success
4343import com.google.samples.apps.nowinandroid.core.analytics.AnalyticsHelper
@@ -108,16 +108,28 @@ class MainActivity : ComponentActivity() {
108108 }
109109
110110 // Turn off the decor fitting system windows, which allows us to handle insets,
111- // including IME animations
112- WindowCompat .setDecorFitsSystemWindows(window, false )
111+ // including IME animations, and go edge-to-edge
112+ // This also sets up the initial system bar style based on the platform theme
113+ enableEdgeToEdge()
113114
114115 setContent {
115- val systemUiController = rememberSystemUiController()
116116 val darkTheme = shouldUseDarkTheme(uiState)
117117
118- // Update the dark content of the system bars to match the theme
119- DisposableEffect (systemUiController, darkTheme) {
120- systemUiController.systemBarsDarkContentEnabled = ! darkTheme
118+ // Update the edge to edge configuration to match the theme
119+ // This is the same parameters as the default enableEdgeToEdge call, but we manually
120+ // resolve whether or not to show dark theme using uiState, since it can be different
121+ // than the configuration's dark theme value based on the user preference.
122+ DisposableEffect (darkTheme) {
123+ enableEdgeToEdge(
124+ statusBarStyle = SystemBarStyle .auto(
125+ android.graphics.Color .TRANSPARENT ,
126+ android.graphics.Color .TRANSPARENT ,
127+ ) { darkTheme },
128+ navigationBarStyle = SystemBarStyle .auto(
129+ lightScrim,
130+ darkScrim,
131+ ) { darkTheme },
132+ )
121133 onDispose {}
122134 }
123135
@@ -224,3 +236,15 @@ private fun shouldUseDarkTheme(
224236 DarkThemeConfig .DARK -> true
225237 }
226238}
239+
240+ /* *
241+ * The default light scrim, as defined by androidx and the platform:
242+ * https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:activity/activity/src/main/java/androidx/activity/EdgeToEdge.kt;l=35-38;drc=27e7d52e8604a080133e8b842db10c89b4482598
243+ */
244+ private val lightScrim = android.graphics.Color .argb(0xe6 , 0xFF , 0xFF , 0xFF )
245+
246+ /* *
247+ * The default dark scrim, as defined by androidx and the platform:
248+ * https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:activity/activity/src/main/java/androidx/activity/EdgeToEdge.kt;l=40-44;drc=27e7d52e8604a080133e8b842db10c89b4482598
249+ */
250+ private val darkScrim = android.graphics.Color .argb(0x80 , 0x1b , 0x1b , 0x1b )
0 commit comments