Basic Color Animation State Changes in Jetpack Compose


Creating a smooth color transition is easy! This animation shifts the color of the leaf from green to red in exactly two seconds (2000 milliseconds).

Leaf.kt

var clicked by remember { mutableStateOf(false) }
val leafColor by animateColorAsState(
targetValue = if (clicked) Color.Red else Color.Green,
animationSpec = tween(2000)
)
drawPath(path = path, brush = SolidColor(leafColor))


Full code here: https://gist.github.com/PopularPenguin/ae7e33dc16d6c1db597a5141f2e37e9d

Comments

Popular posts from this blog

Permissions in Jetpack Compose

Jetpack Compose Login UI

Card Animations in Jetpack Compose