https://kotlinlang.org logo
#compose
Title
# compose
m

Mehdi Haghgoo

03/25/2022, 9:24 AM
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

Chris Sinco [G]

03/25/2022, 9:30 AM
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

Mehdi Haghgoo

03/25/2022, 9:31 AM
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

Chris Sinco [G]

03/25/2022, 9:31 AM
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
8 Views