Skip to content

Instantly share code, notes, and snippets.

@damianpetla
Last active January 9, 2022 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damianpetla/d3c2a8215807d3a1c4463820ece34272 to your computer and use it in GitHub Desktop.
Save damianpetla/d3c2a8215807d3a1c4463820ece34272 to your computer and use it in GitHub Desktop.
// somwhere in the theming code
data class MyTypography(
val bigText: TextStyle = TextStyle(
fontFamily = FontFamily.Monospace,
fontSize = 16.sp,
fontWeight = FontWeight.Bold
),
val smallText: TextStyle = TextStyle(
fontFamily = FontFamily.Monospace,
fontSize = 16.sp,
fontWeight = FontWeight.Bold
)
)
val LocalSimpleTypography = staticCompositionLocalOf { MyTypography() }
object CustomTheme {
val dimensions
@Composable
@ReadOnlyComposable
get() = LocalDimensions.current
val typography
@Composable
@ReadOnlyComposable
get() = LocalSimpleTypography.current
}
// somewhere at the top level of your UI hierarchy
CompositionLocalProvider(
LocalDimensions provides Dimensions(),
LocalSimpleTypography provides MyTypography()
) {
MaterialTheme(
colors = colors,
shapes = Shapes,
content = content
)
}
// somewhere in the layouts
Text(
text = "Hello",
style = CustomTheme.typography.bigText
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment