https://kotlinlang.org logo
#compose
Title
# compose
a

alorma

10/27/2020, 5:11 PM
Hi! One question... What's the best way to have a list of themes? SO we can create a theme switcher
j

Javier

10/27/2020, 5:14 PM
For preview or in general?
For first one check this

https://youtu.be/exjL2kGPngI

a

alorma

10/27/2020, 5:16 PM
for "prod"
j

Javier

10/27/2020, 5:18 PM
I would go for a some Enum which I can save in some way in DataStore, so when the user select one theme, you can observe it an apply automatically
a

alorma

10/27/2020, 5:18 PM
Copy code
data class MaterialThemeHolder(
    val name: String,
    val lightColors: Colors,
    val darkColors: Colors,
    val shapes: Shapes,
    val typography: Typography
) {

    @Composable
    fun compile(
        isDark: Boolean = isSystemInDarkTheme(),
        content: @Composable () -> Unit,
    ) {
        MaterialTheme(
            colors = if (isDark) darkColors else lightColors,
            shapes = shapes,
            typography = typography,
            content = content,
        )
    }
}
I went to something like this, as I'm doing a catalog
a

Afzal Najam

10/27/2020, 6:47 PM
Essentially the same thing but with an abstraction layer, this is what the new project wizard creates: https://github.com/AfzalivE/Fun-Compose/blob/main/app/src/main/java/com/afzaln/funcompose/ui/Theme.kt
3 Views