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

John O'Reilly

12/17/2020, 7:58 PM
Next up on SwiftUI/Compose comparison 🙂 ....in SwiftUI I can apply a font to all
Text
elements within something like
HStack
as shown below. Is anything similar possible right now with Compose (or planned)?
Copy code
HStack {
    Text("some text")
    Text("some more text")
}
.font(.caption)
b

Bryan Herbst

12/17/2020, 8:03 PM
Yeah, you can use Ambients (https://developer.android.com/reference/kotlin/androidx/compose/runtime/Ambient) for that. There are a few ambients built into Material, including text style, content color, etc TextStyles are a little bit of an oddball in that you should use
ProvideTextStyle
instead of the usual
Providers
, so the Compose equivalent would look something like:
Copy code
ProvideTextStyle(MaterialTheme.typography.caption) {
  Column {
    Text("some text")
    Text("some more text")
  }
}
👍 1
j

John O'Reilly

12/17/2020, 8:04 PM
ah, interesting, thanks!
k

Kirill Grouchnikov

12/17/2020, 8:11 PM
Probably it'd be best to start with reading on what Compose has, and then ask about specific things that are missing
👍🏻 2
j

John O'Reilly

12/17/2020, 8:17 PM
I do try and keep up with what's in Compose but clearly I missed a few things 🙂
👍 1
k

Kirill Grouchnikov

12/17/2020, 8:19 PM
2 Views