Choose a driver, compose several, and know exactly what happens when one is stopped or replaced.
timing, spring and decay
timing follows a curve for a fixed duration. spring follows physics and has no fixed length. decay starts with a velocity and slows down.
The same drivers accept a number, a ValueXY or a record, so { x, y, opacity } can move together.
Preparing the example…
Spring parameters
Use one parameterization. With none, you get React Native's default spring (tension 40, friction 7). A spring's velocity defaults to the velocity of the trajectory it interrupts.
sequence runs one after another, parallel runs together, stagger starts each after a delay, delay waits and loop repeats. The result is again a controller, so compositions nest.
Preparing the example…
start, stop and reset
Every controller has start(callback?), stop() and reset(). The callback receives { finished }: false when the motion was stopped or replaced.
Starting a new driver on the same value replaces the running one from the current position. There is no jump to either end.
controller.js
const move = timing(value, { toValue: 1, duration: 600 });
move.start(({ finished }) => {
// finished is false when stopped or replaced by a new animation
});
move.stop(); // keeps the value where it is on screen
move.reset(); // returns to where this animation started
Track another value
A live toValue restarts the driver whenever that value changes, like tracking in React Native. follow(target, source) is the same spring connection as a named function.
tracking.js
// A live toValue tracks another value, like React Native tracking.spring(badge, { toValue: pointer, stiffness: 300, damping: 26 }).start();
// follow() is the same connection as a named function.follow(badge, pointer, { stiffness: 300, damping: 26 });
Easing and keyframes
Easing matches React Native: linear, quad, cubic, sin, circle, exp, elastic, back, bounce, bezier and the in, out, inOut helpers. keyframes(value, frames, options) drives one value through several numbers with optional times and repeat.