alorma
10/21/2020, 9:38 AM@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
Javier
10/21/2020, 9:55 AMalorma
10/21/2020, 10:06 AMMaterialTheme
with esteroids... adding some properties, as we can do on android iby adding <attr />
Louis Pullen-Freilich [G]
10/21/2020, 12:03 PMval 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 🙂alorma
10/21/2020, 12:19 PMLouis Pullen-Freilich [G]
10/21/2020, 12:26 PMMaterialTheme.colors
, then no you will need to pass these values explicitly to the components, you can't 'extend' this behavioralorma
10/21/2020, 12:28 PMLouis Pullen-Freilich [G]
10/21/2020, 12:29 PMalorma
10/21/2020, 12:29 PM