Skip to content

Instantly share code, notes, and snippets.

@Barros9
Created July 24, 2022 09:41
Show Gist options
  • Save Barros9/4b4f97da15078adada10f9cec09efd7b to your computer and use it in GitHub Desktop.
Save Barros9/4b4f97da15078adada10f9cec09efd7b to your computer and use it in GitHub Desktop.
Animation Theme
@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