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

Aram Sheroyan

10/13/2021, 3:56 PM
Hi, I am trying to add compose to an existing application that supports a dark mode. In the official docs is shows how we can create a custom theme but the problem is that all the colors are provided as parameters of a data class. In our app we have over 150 color attributes defined for different components. Is there any better way to handle dark mode an colors because I don't think having a data class with 150 parameters is a good idea. Any help is very appreciated.
c

Csaba Kozák

10/14/2021, 8:21 AM
We also have lots of colors, so we broken down them into groups, the main data class only holds the groups. You can do something similar.
Copy code
data class AppColors(
    val primary: Primary = Primary(),
    val secondary: Secondary = Secondary(),
    val state: State = State(),
    val text: Text = Text(),
    val background: Background = Background(),
    val bw: BlackAndWhite = BlackAndWhite(),
    val social: Social = Social(),
    val poi: Poi = Poi()
) {
a

Aram Sheroyan

10/19/2021, 12:54 AM
@Csaba Kozák I am sorry for such a late response and thank you for the answer. In this case is your
Primary()
a data class or an object? Since it has to support a dark theme how do you wrap your colors inside the
Primary()
so they get updated when dark theme is turned on?
With the regular implementation all the colors are set into a mutable set and there are
copy
and
updateColorsFrom
methods for updating them. I can't wrap my head around on how I would do it with grouped colors
c

Csaba Kozák

10/19/2021, 7:47 AM
Primary()
is a data class. We replace the whole
AppColors
when the colors need to be changed. We provide it using a
CompositionLocal
, similar to
MaterialTheme
.
👍 1
a

Aram Sheroyan

10/19/2021, 11:41 PM
Thank you very much! It worked!
👍 1