From fd7caa19e48b260c443c61911fa41d088c5c2136 Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Sun, 10 Nov 2024 13:24:38 +0100 Subject: [PATCH] Fix forced dark theme always using Element theme Change-Id: Ida51fff71e580b993727cd61b4b2ef81d4b0646c --- .../main/kotlin/chat/schildi/theme/ScTheme.kt | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/schildi/theme/src/main/kotlin/chat/schildi/theme/ScTheme.kt b/schildi/theme/src/main/kotlin/chat/schildi/theme/ScTheme.kt index 5e2e236af4..e7210e8020 100644 --- a/schildi/theme/src/main/kotlin/chat/schildi/theme/ScTheme.kt +++ b/schildi/theme/src/main/kotlin/chat/schildi/theme/ScTheme.kt @@ -1,19 +1,22 @@ package chat.schildi.theme +import androidx.activity.ComponentActivity +import androidx.activity.SystemBarStyle +import androidx.activity.enableEdgeToEdge import androidx.compose.foundation.isSystemInDarkTheme -import androidx.compose.material3.ColorScheme +import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.ReadOnlyComposable import androidx.compose.runtime.remember import androidx.compose.runtime.staticCompositionLocalOf import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.toArgb +import androidx.compose.ui.platform.LocalContext import chat.schildi.lib.preferences.ScPrefs import chat.schildi.lib.preferences.value import io.element.android.compound.theme.ElementTheme -import io.element.android.compound.theme.ForcedDarkElementTheme -import io.element.android.compound.theme.toMaterialColorScheme -import io.element.android.compound.tokens.generated.SemanticColors import io.element.android.compound.tokens.sc.ElTypographyTokens import io.element.android.compound.tokens.sc.ExposedTypographyTokens @@ -83,6 +86,7 @@ fun ScTheme( /** * Can be used to force a composable in dark theme. * It will automatically change the system ui colors back to normal when leaving the composition. + * (Copy of io.element.android.compound.theme.ForcedDarkElementTheme but using ScTheme) */ @Composable fun ForcedDarkScTheme( @@ -90,29 +94,28 @@ fun ForcedDarkScTheme( useScTheme: Boolean = ScPrefs.SC_THEME.value(), content: @Composable () -> Unit, ) { - val currentExposures = remember { - // EleLight is default - elementLightScExposures.copy() - }.apply { updateColorsFrom(getThemeExposures(true, useScTheme)) } - CompositionLocalProvider( - LocalScExposures provides currentExposures - ) { - ForcedDarkElementTheme( - lightStatusBar = lightStatusBar, - content = content, - ) - } - /* TODO if !useScTheme do other stuffs - val systemUiController = rememberSystemUiController() val colorScheme = MaterialTheme.colorScheme val wasDarkTheme = !ElementTheme.colors.isLight + val activity = LocalContext.current as? ComponentActivity DisposableEffect(Unit) { onDispose { - systemUiController.applyTheme(colorScheme, wasDarkTheme) + activity?.enableEdgeToEdge( + statusBarStyle = SystemBarStyle.auto( + lightScrim = colorScheme.background.toArgb(), + darkScrim = colorScheme.background.toArgb(), + ), + navigationBarStyle = if (wasDarkTheme) { + SystemBarStyle.dark(Color.Transparent.toArgb()) + } else { + SystemBarStyle.light( + scrim = Color.Transparent.toArgb(), + darkScrim = Color.Transparent.toArgb() + ) + } + ) } } - ElementTheme(darkTheme = true, lightStatusBar = lightStatusBar, content = content) - */ + ScTheme(darkTheme = true, lightStatusBar = lightStatusBar, useScTheme = useScTheme, content = content) } // Calculate the color as if with alpha on white background