mirror of
https://github.com/skydoves/android-developer-roadmap.git
synced 2025-01-13 00:00:02 +03:00
added dynamic colors
This commit is contained in:
parent
d55ecf72d5
commit
d6dbeb82ed
|
@ -16,37 +16,59 @@
|
||||||
|
|
||||||
package io.getstream.androiddeveloperroadmap.ui.theme
|
package io.getstream.androiddeveloperroadmap.ui.theme
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import android.os.Build
|
||||||
import androidx.compose.foundation.isSystemInDarkTheme
|
import androidx.compose.foundation.isSystemInDarkTheme
|
||||||
import androidx.compose.material.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material.darkColors
|
import androidx.compose.material3.darkColorScheme
|
||||||
import androidx.compose.material.lightColors
|
import androidx.compose.material3.dynamicDarkColorScheme
|
||||||
|
import androidx.compose.material3.dynamicLightColorScheme
|
||||||
|
import androidx.compose.material3.lightColorScheme
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.SideEffect
|
||||||
|
import androidx.compose.ui.graphics.toArgb
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.platform.LocalView
|
||||||
|
import androidx.core.view.WindowCompat
|
||||||
|
|
||||||
private val DarkColorPalette = darkColors(
|
private val DarkColorScheme = darkColorScheme(
|
||||||
primary = Purple200,
|
primary = Purple200,
|
||||||
primaryVariant = Purple700,
|
secondary = Purple700,
|
||||||
secondary = Teal200
|
tertiary = Teal200
|
||||||
)
|
)
|
||||||
|
|
||||||
private val LightColorPalette = lightColors(
|
private val LightColorScheme = lightColorScheme(
|
||||||
primary = Purple500,
|
primary = Purple500,
|
||||||
primaryVariant = Purple700,
|
secondary = Purple700,
|
||||||
secondary = Teal200
|
tertiary = Teal200
|
||||||
)
|
)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun AndroidDeveloperRoadmapTheme(
|
fun AndroidDeveloperRoadmapTheme(
|
||||||
darkTheme: Boolean = isSystemInDarkTheme(),
|
darkTheme: Boolean = isSystemInDarkTheme(),
|
||||||
|
dynamicColor: Boolean = true,
|
||||||
content: @Composable () -> Unit
|
content: @Composable () -> Unit
|
||||||
) {
|
) {
|
||||||
val colors = if (darkTheme) {
|
val colorScheme = when {
|
||||||
DarkColorPalette
|
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
|
||||||
} else {
|
val context = LocalContext.current
|
||||||
LightColorPalette
|
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
|
||||||
|
}
|
||||||
|
|
||||||
|
darkTheme -> DarkColorScheme
|
||||||
|
else -> LightColorScheme
|
||||||
|
}
|
||||||
|
val view = LocalView.current
|
||||||
|
if (!view.isInEditMode) {
|
||||||
|
SideEffect {
|
||||||
|
val window = (view.context as Activity).window
|
||||||
|
window.statusBarColor = colorScheme.primary.toArgb()
|
||||||
|
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MaterialTheme(
|
MaterialTheme(
|
||||||
colors = colors,
|
colorScheme = colorScheme,
|
||||||
typography = Typography,
|
typography = Typography,
|
||||||
shapes = Shapes,
|
shapes = Shapes,
|
||||||
content = content
|
content = content
|
||||||
|
|
Loading…
Reference in a new issue