Skip to content

Commit

Permalink
Fix forced dark theme always using Element theme
Browse files Browse the repository at this point in the history
Change-Id: Ida51fff71e580b993727cd61b4b2ef81d4b0646c
  • Loading branch information
SpiritCroc committed Nov 10, 2024
1 parent c06058b commit fd7caa1
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions schildi/theme/src/main/kotlin/chat/schildi/theme/ScTheme.kt
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -83,36 +86,36 @@ 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(
lightStatusBar: Boolean = false,
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
Expand Down

0 comments on commit fd7caa1

Please sign in to comment.