Animator
A stateless, time-driven computation engine that produces animation values.
An Animator is created by an AnimationSpec with specific initial conditions (initial value, target value, initial velocity) baked in. Once created, it can be queried at any point in time to produce the current value, velocity, and completion status.
Stateless Time-Driven Model
The animator is a pure function of elapsed time — calling getValue with the same playTimeNanos always produces the same result. This enables:
Deterministic replay: Same inputs produce same outputs regardless of frame timing.
Testability: Tests can evaluate at arbitrary time points without running a real clock.
Interruption: Current value and velocity can be captured at any moment and used as initial conditions for a new animator.
Usage
Animators are not created directly — they are produced by AnimationSpec.createAnimator:
val spec = spring<Float>()
val animator = spec.createAnimator(
initialValue = 0f,
targetValue = 1f,
typeConverter = FloatTypeConverter,
)
// Query at specific times
val valueAt100ms = animator.getValue(100_000_000L) // 100ms in nanos
val velocity = FloatTypeConverter.newVector()
animator.getVelocity(100_000_000L, velocity)
val done = animator.isFinished(100_000_000L)Parameters
The type of value this animator produces.
See also
Functions
Writes the current per-component velocity at the given elapsed time into velocity, in float-space units per second.
Returns whether the animation has reached its final state at the given elapsed time.