Fix issue.

This commit is contained in:
Benoit Marty 2023-02-03 10:46:06 +01:00 committed by Benoit Marty
parent 56cb19707b
commit 579693354a
2 changed files with 26 additions and 16 deletions

View file

@ -16,9 +16,12 @@
package io.element.android.libraries.designsystem.theme package io.element.android.libraries.designsystem.theme
import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.ColorScheme import androidx.compose.material3.ColorScheme
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.ReadOnlyComposable import androidx.compose.runtime.ReadOnlyComposable
@ -26,6 +29,7 @@ import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.staticCompositionLocalOf import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import com.google.accompanist.systemuicontroller.rememberSystemUiController import com.google.accompanist.systemuicontroller.rememberSystemUiController
/** /**
@ -44,6 +48,7 @@ val LocalColors = staticCompositionLocalOf { elementColorsLight() }
@Composable @Composable
fun ElementTheme( fun ElementTheme(
darkTheme: Boolean = isSystemInDarkTheme(), darkTheme: Boolean = isSystemInDarkTheme(),
dynamicColor: Boolean = false, /* true to enable MaterialYou */
lightColors: ElementColors = elementColorsLight(), lightColors: ElementColors = elementColorsLight(),
darkColors: ElementColors = elementColorsDark(), darkColors: ElementColors = elementColorsDark(),
materialLightColors: ColorScheme = materialColorSchemeLight, materialLightColors: ColorScheme = materialColorSchemeLight,
@ -53,25 +58,31 @@ fun ElementTheme(
val systemUiController = rememberSystemUiController() val systemUiController = rememberSystemUiController()
val useDarkIcons = !darkTheme val useDarkIcons = !darkTheme
val currentColor = remember { if (darkTheme) darkColors else lightColors } val currentColor = remember { if (darkTheme) darkColors else lightColors }
val colorScheme = when {
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
val context = LocalContext.current
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
}
darkTheme -> materialDarkColors
else -> materialLightColors
}
SideEffect {
systemUiController.setStatusBarColor(
color = colorScheme.background
)
systemUiController.setSystemBarsColor(
color = Color.Transparent,
darkIcons = useDarkIcons
)
}
val rememberedColors = remember { currentColor.copy() }.apply { updateColorsFrom(currentColor) } val rememberedColors = remember { currentColor.copy() }.apply { updateColorsFrom(currentColor) }
CompositionLocalProvider( CompositionLocalProvider(
LocalColors provides rememberedColors, LocalColors provides rememberedColors,
) { ) {
MaterialTheme( MaterialTheme(
colorScheme = if (darkTheme) materialDarkColors else materialLightColors colorScheme = colorScheme,
) { // TODO typography =
val bgColor = MaterialTheme.colorScheme.background content = content
SideEffect { )
systemUiController.setStatusBarColor(
color = bgColor
)
systemUiController.setSystemBarsColor(
color = Color.Transparent,
darkIcons = useDarkIcons
)
}
content()
}
} }
} }

View file

@ -18,7 +18,6 @@ package io.element.android.libraries.designsystem.theme.components
import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.SliderColors import androidx.compose.material3.SliderColors
import androidx.compose.material3.SliderDefaults import androidx.compose.material3.SliderDefaults
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable