AnimationSpec
An immutable configuration that defines how an animation should behave.
AnimationSpec is a lightweight, shareable description of animation parameters — spring stiffness, tween duration, easing curve, etc. It does not hold animation state. When an animation needs to run, createAnimator produces an Animator bound to specific initial conditions.
Spec vs Animator
AnimationSpec = recipe (what kind of animation, reusable)
Animator = computation engine (bound to specific from/to values, time-driven)
Built-in Specs
spring<Float>(stiffness = Stiffness.Low, dampingRatio = DampingRatio.MediumBouncy)
tween<Float>(duration = 300.ms, easing = Easing.FastOutSlowIn)
keyframes<Float>(duration = 500.ms) { ... }
snap<Float>()
repeatable<Float>(iterations = 3, animation = tween())Type Safety
AnimationSpec is parameterized by the value type T. The TypeConverter is provided at animator creation time — not at spec construction time — so a single spec like spring<Float>() is both lightweight and type-safe without needing to carry a converter reference.
Interruption
When an animation is interrupted mid-flight, the current per-component velocity can be captured from the running Animator and passed as initialVelocity to a new animator. This enables smooth retargeting without velocity discontinuities.
// Interruption with per-component velocity preservation
val velocity = FloatTypeConverter.newVector()
runningAnimator.getVelocity(elapsedNanos, velocity)
val newAnimator = spec.createAnimator(
initialValue = currentValue,
targetValue = newTarget,
typeConverter = FloatTypeConverter,
initialVelocity = velocity,
)Parameters
The type of value this spec animates.
See also
Inheritors
Functions
Creates an Animator configured with the given initial conditions.