Hi all, what is the point of passing a Typography ...
# compose
a
Hi all, what is the point of passing a Typography into the MaterialTheme for material3? isn't it equally easy to have a typography object in the project and write
Copy code
Text(
   text = "text",
   style = Typography.bodyMedium // instead of MaterialTheme.typography.bodyMedium
)
s
Uhm sure, but the material3 components take the values that they want from inside the Material3 LocalColorScheme, LocalTypography and so on. MaterialTheme is just an object which has those functions which fetch the values from inside the composition locals, nothing more special than that.
a
Doing it that way will ignore any intermediate parent theming. So if you have a composable that gets wrapped in a copy of a material theme, this inner composable won’t respect it. As I understand it
s
Oh yeah if you meant not even going through composition locals then you're setting yourself up for failure once you have any place that does
ProvideTextStyle
or any other way you want to override for all children
a
that makes sense, wasn't planning on having more than one theme or typography at any point but probably worth the minor overhead to be on the safe side
s
Not having more than one theme sounds reasonable yeah, but you still want the locals approach so that you're able to do stuff like this https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/material3/material3/src/commonMain/kotlin/androidx/compose/material3/TextFieldImpl.kt;l=267-280 material3 TextField does make use of this functionality so that it can have parts of a composable be automatically provided the right typography https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/material3/material3/src/commonMain/kotlin/androidx/compose/material3/TextFieldImpl.kt;l=161-172 style in a local, so that if you do nothing it has the right style, but you can still overwrite it on your specific composables by passing an explicit type instead of relying on the composition local.