Created
July 24, 2022 09:41
-
-
Save Barros9/4b4f97da15078adada10f9cec09efd7b to your computer and use it in GitHub Desktop.
Animation Theme
This file contains hidden or 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 ComposeFunctionsTheme( | |
darkTheme: Boolean = isSystemInDarkTheme(), | |
content: @Composable () -> Unit | |
) { | |
val palette = if (darkTheme) { DarkColorPalette } else { LightColorPalette } | |
MaterialTheme( | |
colors = palette.switch(), | |
typography = Typography, | |
shapes = Shapes, | |
content = content | |
) | |
} | |
@Composable | |
private fun animateColor(targetValue: Color) = | |
animateColorAsState( | |
targetValue = targetValue, | |
animationSpec = tween(durationMillis = 2000) | |
).value | |
@Composable | |
fun Colors.switch() = copy( | |
primary = animateColor(primary), | |
primaryVariant = animateColor(primaryVariant), | |
secondary = animateColor(secondary), | |
secondaryVariant = animateColor(secondaryVariant), | |
background = animateColor(background), | |
surface = animateColor(surface), | |
error = animateColor(error), | |
onPrimary = animateColor(onPrimary), | |
onSecondary = animateColor(onSecondary), | |
onBackground = animateColor(onBackground), | |
onSurface = animateColor(onSurface), | |
onError = animateColor(onError) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment