Interrupting and stopping
Starting an animation on a property that's already animating takes it over: the new one starts from the value on screen, with the same velocity, so a card can change its mind halfway without a jump. Other properties of the previous animation keep going.
animate() returns an animation you can await. It resolves with true when it played to the end, and false when it was stopped or taken over. It never rejects.
const animation = animate(card, { x: 300 })
animation.stop() // the card stays where it is
stop(card) // stops everything running on the card
stop(card, ['x', 'scale']) // stops translation on x and both scale axesSelected properties stay at their current values; the others keep animating. scaleX and scaleY can also be stopped separately. Pass an empty array to stop nothing, or omit it to stop everything. This works with arrays of targets too.
If part of an animation is stopped, its finished promise resolves with false once its remaining properties finish.
Setting values without animating
set() places a view without animating it, for a reduced-motion layout, a reset before a loop, or a state that should simply be there:
set(logo, { opacity: 1, scale: 1, y: 0 })
set(card, { backgroundColor: '#fff' })It takes one value per property, with the same properties as animate(), including colors and decorations. Whatever animates those properties stops, and its finished resolves with false; other properties keep animating. The next animate() starts from the set value with no velocity. A view that isn't loaded yet gets the values right away, and they win over an animation that is still waiting for that view to load.
Loops and the background
Infinite repeats keep playing natively. On iOS, Core Animation drops animations when the app goes to the background; Jolt starts them again when it comes back.
For holding an animation and choosing its frame, see pause, play and scrub.