Last active
May 5, 2021 23:42
-
-
Save rahulsainani/97e62da864572914720984b1f56f0296 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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