Why we have ProvideTextStyle() and not also Provid...
# compose
m
Why we have ProvideTextStyle() and not also ProvideShape() and ProvideColors()? We access theme values from within the theme object (MaterialTheme object), so why do we need to use ProvideTextStyle(value){content()} in the first place?
c
You don't need to use it unless you are trying to simplify passing theme styles down through a hierarchy. In fact, we caution against using CompositionLocals in general. This guide provides more detail: https://developer.android.com/jetpack/compose/compositionlocal#deciding
❤️ 1
m
And surprisingly, providing a textStyle with CompositionLocalProvider(LocalTextStyle provides myStyle){ MaterialTheme( /* colors = ..., shapes = .., */ content = content } does not have the same effect as ProvideTextStyle (updating the value of LocalTextStyle).
c
It's likely ProvideShape and ProvideColor don't exist out of the box specifically because we encourage using MaterialTheme. But Text tends to be more complicated so we have ProvideTextStyle for convenience. But, as stated above, use with full awareness of how it works before creating custom Provides
❤️ 1