mattinger
10/01/2020, 12:57 PMvar primary by mutableStateOf(primary, structuralEqualityPolicy())
internal set
Louis Pullen-Freilich [G]
10/01/2020, 1:23 PMI imagine maybe it’s helpful for the recomposer so that it doesn’t have to rebuild the full component tree if colors change, it can just adjust the color of the individual elements, but i’d like to confirm that.Exactly, it's very common for colors to change when switching between themes, or when animating one color in the theme (such as
primary
), so by having each color backed with mutableStateOf
only components that read that particular color will be recomposed.
On the other hand Typography
is much more static, and barely ever changes - so there's not much point in having the same optimization there. Same for Shapes
.