Browse Source

Merge pull request #1225 from vector-im/feature/bma/forceDarkTheme

Fix system bar color after login on light theme.
pull/1229/head
Benoit Marty 1 year ago committed by GitHub
parent
commit
d4b527fb80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      changelog.d/1222.bugfix
  2. 5
      libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/atomic/pages/SunsetPage.kt
  3. 17
      libraries/theme/src/main/kotlin/io/element/android/libraries/theme/ElementTheme.kt

1
changelog.d/1222.bugfix

@ -0,0 +1 @@ @@ -0,0 +1 @@
Fix system bar color after login on light theme.

5
libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/atomic/pages/SunsetPage.kt

@ -44,6 +44,7 @@ import io.element.android.libraries.designsystem.text.withColoredPeriod @@ -44,6 +44,7 @@ import io.element.android.libraries.designsystem.text.withColoredPeriod
import io.element.android.libraries.designsystem.theme.components.CircularProgressIndicator
import io.element.android.libraries.designsystem.theme.components.Text
import io.element.android.libraries.theme.ElementTheme
import io.element.android.libraries.theme.ForcedDarkElementTheme
@Composable
fun SunsetPage(
@ -53,9 +54,7 @@ fun SunsetPage( @@ -53,9 +54,7 @@ fun SunsetPage(
modifier: Modifier = Modifier,
overallContent: @Composable () -> Unit,
) {
ElementTheme(
darkTheme = true
) {
ForcedDarkElementTheme(lightStatusBar = true) {
Box(
modifier = modifier.fillMaxSize()
) {

17
libraries/theme/src/main/kotlin/io/element/android/libraries/theme/ElementTheme.kt

@ -92,6 +92,7 @@ internal val LocalCompoundColors = staticCompositionLocalOf { compoundColorsLigh @@ -92,6 +92,7 @@ internal val LocalCompoundColors = staticCompositionLocalOf { compoundColorsLigh
@Composable
fun ElementTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
lightStatusBar: Boolean = !darkTheme,
dynamicColor: Boolean = false, /* true to enable MaterialYou */
compoundColors: SemanticColors = if (darkTheme) compoundColorsDark else compoundColorsLight,
materialLightColors: ColorScheme = materialColorSchemeLight,
@ -111,8 +112,19 @@ fun ElementTheme( @@ -111,8 +112,19 @@ fun ElementTheme(
darkTheme -> materialDarkColors
else -> materialLightColors
}
val statusBarColorScheme = if (lightStatusBar) {
when {
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
val context = LocalContext.current
dynamicLightColorScheme(context)
}
else -> materialLightColors
}
} else {
colorScheme
}
SideEffect {
systemUiController.applyTheme(colorScheme = colorScheme, darkTheme = darkTheme)
systemUiController.applyTheme(colorScheme = statusBarColorScheme, darkTheme = darkTheme && !lightStatusBar)
}
CompositionLocalProvider(
LocalCompoundColors provides currentCompoundColor,
@ -132,6 +144,7 @@ fun ElementTheme( @@ -132,6 +144,7 @@ fun ElementTheme(
*/
@Composable
fun ForcedDarkElementTheme(
lightStatusBar: Boolean = false,
content: @Composable () -> Unit,
) {
val systemUiController = rememberSystemUiController()
@ -142,7 +155,7 @@ fun ForcedDarkElementTheme( @@ -142,7 +155,7 @@ fun ForcedDarkElementTheme(
systemUiController.applyTheme(colorScheme, wasDarkTheme)
}
}
ElementTheme(darkTheme = true, content = content)
ElementTheme(darkTheme = true, lightStatusBar = lightStatusBar, content = content)
}
private fun SystemUiController.applyTheme(

Loading…
Cancel
Save