Skip to content

Instantly share code, notes, and snippets.

@damianpetla
Last active January 9, 2022 21:07
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/12a576cf714b05b91018ac4bdf4c6a7f to your computer and use it in GitHub Desktop.
Save damianpetla/12a576cf714b05b91018ac4bdf4c6a7f to your computer and use it in GitHub Desktop.
// somewhere in the theming code
data class Dimensions(
val tiny: Dp = 4.dp,
val mediocre: Dp = 16.dp,
val craaaazy: Dp = 100.dp
)
val LocalDimensions = staticCompositionLocalOf { Dimensions() }
val MaterialTheme.dimensions
@Composable
@ReadOnlyComposable
get() = LocalDimensions.current
// somewhere at top level of your UI hierarchy
CompositionLocalProvider(LocalDimensions provides Dimensions()) {
MaterialTheme(
colors = colors,
typography = Typography,
shapes = Shapes,
content = content
)
}
// somewhere in the layouts
Surface(modifier = Modifier.padding(MaterialTheme.dimensions.craaaazy)) {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment