Skip to content

Instantly share code, notes, and snippets.

@rahulsainani
Last active May 5, 2021 23:42
Show Gist options
  • Save rahulsainani/97e62da864572914720984b1f56f0296 to your computer and use it in GitHub Desktop.
Save rahulsainani/97e62da864572914720984b1f56f0296 to your computer and use it in GitHub Desktop.
@Composable
fun ProvideDimens(
dimensions: Dimensions,
content: @Composable () -> Unit
) {
val dimensionSet = remember { dimensions }
CompositionLocalProvider(LocalAppDimens provides dimensionSet, content = content)
}
private val LocalAppDimens = staticCompositionLocalOf {
smallDimensions
}
@Composable
fun AppTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
content: @Composable () -> Unit
) {
val colors = if (darkTheme) DarkThemeColors else LightThemeColors
val configuration = LocalConfiguration.current
val dimensions = if (configuration.screenWidthDp <= 360) smallDimensions else sw360Dimensions
val typography = if (configuration.screenWidthDp <= 360) smallTypography else sw360Typography
ProvideDimens(dimensions = dimensions) {
ProvideColors(colors = colors) {
MaterialTheme(
colors = colors,
shapes = Shapes,
typography = typography,
content = content,
)
}
}
}
object AppTheme {
val colors: Colors
@Composable
get() = LocalAppColors.current
val dimens: Dimensions
@Composable
get() = LocalAppDimens.current
}
val Dimens: Dimensions
@Composable
get() = AppTheme.dimens
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment