When working with custom design specs (Typography,...
# compose
i
When working with custom design specs (Typography, Colors, etc.) where you already have defined the only values a spec could take does it make any sense to work with classes that then need to be provided (via CompositionLocals) and not use objects directly? In the documentation they use a
data class CustomColors
and then a
staticCompositionLocalOf
but... does it make sense to omit all of this if we use an object instead?
c
Do you have an example of where you are trying to do this in your app?
The custom theming in the documentation results in a similar theming system as MaterialTheme, so if you need to make local overrides on top of your custom theme, I’d do it the same way you’d do it on MaterialTheme through CompositionLocal or creating higher-level Composables that wrap your custom theme and pass in different values
b
We use a combination. Typography is an object. Colors are a class, but consumers can’t actually change any of them (the constructor is not visible)- it is a class so we can offer both light and dark mode instances. The most consumers can do is force one mode or the other.
i
ok @Bryan Herbst that makes sense! with Colors could make sense to treat it as a class and the be provided because it can be changed modified
@Chris Sinco [G] the thing is I will have to create “wrappers” for Material Components like button anyways because the defaults they provide point to
MaterialTheme.whatever
. With MaterialTheme you have a Typography class which defines h1, h2… and then the consumer creates an instance with the specific values for h1, h2… but in my case I do not need this flexibility because I know the only possible TextStyles my spec needs and I don’t need to make “local overrides”. This way I treat Typography as an global object and I don’t need to “provide” it with CompositionLocalProvider. I don’t know if this make sense
c
I think it does though it would help to see code snippets of sample usage in your app of these custom styles in your spec. Though it sounds like you have things working fine? 🤷‍♂️