Thread
#compose
    a

    alorma

    1 year ago
    HI! A question for compose: Is this the best way to create custom colors and shapes values?
    @Composable
    val Colors.success: Color
        get() = if (isSystemInDarkTheme()) {
            green200
        } else {
            green800
        }
    @Composable
    val Shapes.fab: Shape
        get() = RoundedCornerShape(percent = 50)
    MaterialThemes.Colors.success
    MaterialThemes.Shapes.fab
    a

    alorma

    1 year ago
    that was what I read too... not sure if it make sense to create a custom theme for just a few items 😅
    I mean, i want to use
    MaterialTheme
    with esteroids... adding some properties, as we can do on android iby adding
    <attr />
    l

    Louis Pullen-Freilich [G]

    1 year ago
    Side note - the first extension could instead be:
    val Colors.success: Color
        get() = if (!isLight) {
            green200
        } else {
            green800
        }
    Extensions are reasonable for small additions, but they don't scale well as soon as you start having multiple themes. It also becomes easy to change the value in one theme but not change the extensions, since they are loosely connected (in your case by using
    isSystemInDarkTheme
    ). If it is really just a few items, then extensions / providing a separate
    Ambient
    along with the existing theme works, but normally 'just a few items' becomes a lot of items, and at that point it would have been a lot more type safe / expressive / scalable to build a custom theme object in the first place 🙂
    a

    alorma

    1 year ago
    Thanks!
    Will custom theme work, for example, for Surface automatic onColor? @Louis Pullen-Freilich [G]
    Or for material components, like TopAppBar?
    l

    Louis Pullen-Freilich [G]

    1 year ago
    If you create a new theme that is unrelated to the existing
    MaterialTheme.colors
    , then no you will need to pass these values explicitly to the components, you can't 'extend' this behavior
    a

    alorma

    1 year ago
    Uhmm, and can MaterialThemming be extended?
    As I may want to add "warning" and "success" colors
    l

    Louis Pullen-Freilich [G]

    1 year ago
    Nope, you should just create your own theme similar to the Jetsnack example
    a

    alorma

    1 year ago
    grr
    then i will go to my approach on create few "attr" colors
    many thanks