Thread
#compose
    a

    Aram Sheroyan

    11 months ago
    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.
    Csaba Kozák

    Csaba Kozák

    11 months ago
    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.
    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

    11 months ago
    @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
    Csaba Kozák

    Csaba Kozák

    11 months ago
    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
    .
    a

    Aram Sheroyan

    11 months ago
    Thank you very much! It worked!