diff --git a/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/ElementTheme.kt b/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/ElementTheme.kt index 7e7d4d8caf..cbeb84badb 100644 --- a/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/ElementTheme.kt +++ b/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/ElementTheme.kt @@ -16,9 +16,12 @@ package io.element.android.libraries.designsystem.theme +import android.os.Build import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.material3.ColorScheme import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.dynamicDarkColorScheme +import androidx.compose.material3.dynamicLightColorScheme import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.ReadOnlyComposable @@ -26,6 +29,7 @@ import androidx.compose.runtime.SideEffect import androidx.compose.runtime.remember import androidx.compose.runtime.staticCompositionLocalOf import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.LocalContext import com.google.accompanist.systemuicontroller.rememberSystemUiController /** @@ -44,6 +48,7 @@ val LocalColors = staticCompositionLocalOf { elementColorsLight() } @Composable fun ElementTheme( darkTheme: Boolean = isSystemInDarkTheme(), + dynamicColor: Boolean = false, /* true to enable MaterialYou */ lightColors: ElementColors = elementColorsLight(), darkColors: ElementColors = elementColorsDark(), materialLightColors: ColorScheme = materialColorSchemeLight, @@ -53,25 +58,31 @@ fun ElementTheme( val systemUiController = rememberSystemUiController() val useDarkIcons = !darkTheme 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) } CompositionLocalProvider( LocalColors provides rememberedColors, ) { MaterialTheme( - colorScheme = if (darkTheme) materialDarkColors else materialLightColors - ) { - val bgColor = MaterialTheme.colorScheme.background - SideEffect { - systemUiController.setStatusBarColor( - color = bgColor - ) - systemUiController.setSystemBarsColor( - color = Color.Transparent, - darkIcons = useDarkIcons - ) - } - - content() - } + colorScheme = colorScheme, + // TODO typography = + content = content + ) } } diff --git a/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/components/Slider.kt b/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/components/Slider.kt index edefe1ab98..a303e1ba77 100644 --- a/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/components/Slider.kt +++ b/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/components/Slider.kt @@ -18,7 +18,6 @@ package io.element.android.libraries.designsystem.theme.components import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.Column -import androidx.compose.material3.MaterialTheme import androidx.compose.material3.SliderColors import androidx.compose.material3.SliderDefaults import androidx.compose.runtime.Composable