From 9c88a8d20ee2d615af2ecdec92a0f71fecfea622 Mon Sep 17 00:00:00 2001 From: Oliver Spryn <2717340+oliverspryn@users.noreply.github.com> Date: Wed, 7 Feb 2024 10:15:33 -0500 Subject: [PATCH] Add back in commented out code regarding the system status bar --- .../multimodal/sample/ui/theme/Theme.kt | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/app/src/main/kotlin/com/oliverspryn/android/multimodal/sample/ui/theme/Theme.kt b/app/src/main/kotlin/com/oliverspryn/android/multimodal/sample/ui/theme/Theme.kt index ee6df45..08f4c4a 100644 --- a/app/src/main/kotlin/com/oliverspryn/android/multimodal/sample/ui/theme/Theme.kt +++ b/app/src/main/kotlin/com/oliverspryn/android/multimodal/sample/ui/theme/Theme.kt @@ -13,6 +13,7 @@ import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalView import androidx.core.view.ViewCompat +import androidx.core.view.WindowCompat private val DarkColorScheme = darkColorScheme( primary = Purple80, @@ -28,26 +29,32 @@ private val LightColorScheme = darkColorScheme( @Composable fun MultimodalSpannerTheme( - darkTheme: Boolean = isSystemInDarkTheme(), - dynamicColor: Boolean = true, + allowDynamicTheme: Boolean = true, + isDeviceUsingDarkMode: Boolean = isSystemInDarkTheme(), content: @Composable () -> Unit ) { val colorScheme = when { - dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { + allowDynamicTheme && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { val context = LocalContext.current - if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) + if (isDeviceUsingDarkMode) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) } - darkTheme -> DarkColorScheme + isDeviceUsingDarkMode -> DarkColorScheme else -> LightColorScheme } val view = LocalView.current + val isPreviewingInAndroidStudio = view.isInEditMode - if (!view.isInEditMode) { + if (!isPreviewingInAndroidStudio) { SideEffect { - (view.context as Activity).window.statusBarColor = colorScheme.primary.toArgb() - //ViewCompat.getWindowInsetsController(view)?.isAppearanceLightStatusBars = darkTheme + val activity = view.context as Activity + activity.window.statusBarColor = colorScheme.primary.toArgb() + + WindowCompat.getInsetsController( + activity.window, + view + ).isAppearanceLightStatusBars = isDeviceUsingDarkMode } }