app: add dynamic colors support to Compose

This commit is contained in:
Harsh Shandilya 2021-11-03 16:02:58 +05:30
parent 3fc5f17920
commit 2a9d2177a5
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80

View file

@ -1,8 +1,11 @@
package dev.msfjarvis.aps.ui.theme package dev.msfjarvis.aps.ui.theme
import android.content.Context
import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.material3.lightColorScheme import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
@ -64,12 +67,16 @@ private val DarkThemeColors =
) )
@Composable @Composable
fun APSTheme(useDarkTheme: Boolean = isSystemInDarkTheme(), content: @Composable () -> Unit) { fun APSTheme(
useDynamicColors: Boolean = true,
useDarkTheme: Boolean = isSystemInDarkTheme(),
context: Context,
content: @Composable () -> Unit,
) {
val colors = val colors =
if (!useDarkTheme) { when (useDarkTheme) {
LightThemeColors true -> if (useDynamicColors) dynamicDarkColorScheme(context) else DarkThemeColors
} else { false -> if (useDynamicColors) dynamicLightColorScheme(context) else LightThemeColors
DarkThemeColors
} }
MaterialTheme(colorScheme = colors, typography = AppTypography, content = content) MaterialTheme(colorScheme = colors, typography = AppTypography, content = content)