@@ -17,7 +17,6 @@ package com.example.affirmations.ui.theme
1717
1818import android.app.Activity
1919import android.os.Build
20- import android.view.View
2120import androidx.compose.foundation.isSystemInDarkTheme
2221import androidx.compose.material3.MaterialTheme
2322import androidx.compose.material3.darkColorScheme
@@ -26,7 +25,6 @@ import androidx.compose.material3.dynamicLightColorScheme
2625import androidx.compose.material3.lightColorScheme
2726import androidx.compose.runtime.Composable
2827import androidx.compose.runtime.SideEffect
29- import androidx.compose.ui.graphics.Color
3028import androidx.compose.ui.graphics.toArgb
3129import androidx.compose.ui.platform.LocalContext
3230import androidx.compose.ui.platform.LocalView
@@ -60,10 +58,13 @@ fun AffirmationsTheme(
6058 darkTheme -> DarkColorScheme
6159 else -> LightColorScheme
6260 }
61+
6362 val view = LocalView .current
6463 if (! view.isInEditMode) {
6564 SideEffect {
66- setUpEdgeToEdge(view, darkTheme)
65+ val window = (view.context as Activity ).window
66+ window.statusBarColor = colorScheme.background.toArgb()
67+ WindowCompat .getInsetsController(window, view).isAppearanceLightStatusBars = ! darkTheme
6768 }
6869 }
6970
@@ -72,23 +73,3 @@ fun AffirmationsTheme(
7273 content = content
7374 )
7475}
75-
76- /* *
77- * Sets up edge-to-edge for the window of this [view]. The system icon colors are set to either
78- * light or dark depending on whether the [darkTheme] is enabled or not.
79- */
80- private fun setUpEdgeToEdge (view : View , darkTheme : Boolean ) {
81- val window = (view.context as Activity ).window
82- WindowCompat .setDecorFitsSystemWindows(window, false )
83- window.statusBarColor = Color .Transparent .toArgb()
84- val navigationBarColor = when {
85- Build .VERSION .SDK_INT >= 29 -> Color .Transparent .toArgb()
86- Build .VERSION .SDK_INT >= 26 -> Color (0xFF , 0xFF , 0xFF , 0x63 ).toArgb()
87- // Min sdk version for this app is 24, this block is for SDK versions 24 and 25
88- else -> Color (0x00 , 0x00 , 0x00 , 0x50 ).toArgb()
89- }
90- window.navigationBarColor = navigationBarColor
91- val controller = WindowCompat .getInsetsController(window, view)
92- controller.isAppearanceLightStatusBars = ! darkTheme
93- controller.isAppearanceLightNavigationBars = ! darkTheme
94- }
0 commit comments