Gesture and Spring Animations
Natural, physics-based motion.
Interactive, Physical Motion
The most delightful animations respond to the user's finger and feel like real objects, with momentum and bounce. To build these you combine gestures with physics-based animation.
This lesson covers Animatable, springs, fling decay, and wiring them to drag gestures for natural, interactive UI.
Animatable: Low-Level Control
While animate*AsState reacts to state, Animatable gives you imperative control. You hold one in remember and drive it from a coroutine with calls like animateTo or snapTo.
This is the foundation for gesture-driven motion.
@Composable
fun BounceOnClick() {
val scale = remember { Animatable(1f) }
val scope = rememberCoroutineScope()
Box(
Modifier
.graphicsLayer { scaleX = scale.value; scaleY = scale.value }
.clickable {
scope.launch {
scale.animateTo(1.3f, spring())
scale.animateTo(1f, spring())
}
}
)
}All lessons in this course
- Why Animations Matter
- animate*AsState Basics
- AnimatedVisibility and Transitions
- Gesture and Spring Animations