Skip to content

Instantly share code, notes, and snippets.

@llama-0
Created August 17, 2021 09:58
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 llama-0/4c65f4aa7fdccf8b35ca089f6b30fac1 to your computer and use it in GitHub Desktop.
Save llama-0/4c65f4aa7fdccf8b35ca089f6b30fac1 to your computer and use it in GitHub Desktop.
package ru.llama.core.presentation.theme
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.runtime.staticCompositionLocalOf
object AppTheme {
val colors: AppColors
@Composable
@ReadOnlyComposable
get() = LocalAppColors.current
val typography: AppTypography
@Composable
@ReadOnlyComposable
get() = LocalAppTypography.current
}
private val LocalAppColors = staticCompositionLocalOf {
defaultAppColors()
}
private val LocalAppTypography = staticCompositionLocalOf {
defaultAppTypography()
}
@Composable
fun AppTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
colors: AppColors = appColors(darkTheme = darkTheme),
typography: AppTypography = appTypography(TextStyles(colors)),
content: @Composable () -> Unit,
) {
CompositionLocalProvider(
LocalAppColors provides colors,
LocalAppTypography provides typography,
) {
MaterialTheme(
colors = colors.materialColors,
typography = typography.materialTypography,
shapes = Shapes,
content = content,
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment