Animations: who draws the next frame?
An animation is sixty values a second. Watch Animated's three curves draw themselves, then keep the JS thread busy and see which way of computing those values drops frames and which doesn't.
What you'll take away
- Tell Animated's timing, spring and decay apart, and pick the one a motion needs
- Explain why
useNativeDriver: falseloses frames while JS is busy: a stop, then a jump - Hand an animation to native with
useNativeDriver: true, and know which styles it takes - Fix 'not supported by native animated module' with scaleX, or Reanimated for width
The 1-minute version
Tap a point and the picture below plays that step.
Run it, then quickly keep JS busy. Try all three, then try width with the native driver
You fade a button with Animated and want it smooth while JS is loading data. What do you set?
The picture: a big phone standing in the night city, with a ball (or a bar) on its screen that the animation moves, drawn as its user sees it. Up the street the UI thread's hall draws the screen; behind it stands the JS thread's hall, a bridge between the two. A JS-driven animation sends every frame over the bridge as a light; a native-driver or Reanimated one crosses once, before it starts. The lights are slower than in life, and the steps play at half speed. The curves come from Animated's own formulas; the frames are a model at 60 a second, not a measurement of a real phone.
Compare them all: Animations on a phone
The same animation, there and back, while JS is busy for most of a second (a heavy render). See which one loses frames.
Use it when Styles the native driver won't take, on screens where JS is surely idle meanwhile
Skip it when Animations during data loading or a screen change, when JS is busiest
A model at 60 frames a second, not measured on a phone. Press any tile to see it large above, with when it fits.
Who computes the frames
| Way | Each frame on | Styles | While JS is busy |
|---|---|---|---|
| Animated, useNativeDriver: false | JS | any | frames lost |
| Animated, useNativeDriver: true | native | non-layout: transform, opacity, colours | smooth |
| Reanimated (worklets) | UI thread | any, layout included | smooth |
Following a scroll
Animated.event maps onScroll's contentOffset.y onto an Animated.Value. With useNativeDriver: true the header follows the scroll natively, no JS per frame. It works with direct events like onScroll, not with PanResponder, whose moves come through JS.
In real code
// Animated with the native driver: the whole animation is handed to native before it starts, so a busy JS thread
// can't drop its frames. It takes non-layout styles only (transform, opacity, colours).
import { useEffect, useRef } from "react";
import { Animated, Easing, Text } from "react-native";
export function Toast({ message, onHidden }: { message: string; onHidden: () => void }) {
const shown = useRef(new Animated.Value(0)).current;
useEffect(() => {
Animated.sequence([
// timing: 0 → 1 in a set time (500 ms and Easing.inOut(Easing.ease) are its defaults; written out here)
Animated.timing(shown, { toValue: 1, duration: 500, easing: Easing.inOut(Easing.ease), useNativeDriver: true }),
Animated.delay(1800),
// spring: no fixed duration, physics (it may go a little past, then settle)
Animated.spring(shown, { toValue: 0, stiffness: 100, damping: 10, mass: 1, useNativeDriver: true }),
]).start(({ finished }) => { if (finished) onHidden(); });
}, [shown, onHidden]);
return (
<Animated.View
style={{
opacity: shown,
transform: [{ translateY: shown.interpolate({ inputRange: [0, 1], outputRange: [40, 0] }) }],
// width: shown.interpolate(…) here would be refused:
// "Style property 'width' is not supported by native animated module"
}}
>
<Text>{message}</Text>
</Animated.View>
);
}
// decay: no target, it starts at a velocity (say, a flick's) and slows by `deceleration` per ms until it stops.
export function glide(x: Animated.Value, velocity: number) {
Animated.decay(x, { velocity, deceleration: 0.998, useNativeDriver: true }).start();
}
tsc against each library's own published types (react-native and the libraries this file imports); type-checked only, never run on a phoneIt printed: tsc 6.0.3 (strict): no errors against react-native 0.88.1 (type-checked only)Animated with the native driver: timing in, spring out, decay for a flick, opacity and transform only. Type-checked with tsc against the types react-native 0.88 publishes; no phone ran it.
Common questions
timing, spring, decay: what's the difference?
timing reaches a set value in a set time (500 ms by default). spring uses spring physics and may go past and swing back. decay has no target: it starts at a velocity and slows until it stops.
Why does my animation stutter while the app is loading?
With useNativeDriver: false every frame waits for JS to compute it, and while loading JS is busy rendering or parsing, so frames are lost. Moving the work to native or the UI thread fixes it.
What does useNativeDriver: true do?
Before it starts, Animated sends the whole animation's description to native; from then on native computes each frame itself, with no trip back to JS per frame.
What is the 'not supported by native animated module' error?
The native driver only takes non-layout styles such as transform, opacity and colours. Send it width, height, top or margin and you get this error. Switch to a transform like scaleX, or use Reanimated.
When should I use Reanimated?
When an animation follows a finger, must be interruptible, or moves layout like width. Reanimated runs it as a worklet on the UI thread and can move any style.
How do I make a scroll-linked animation smooth?
Use Animated.event to wire onScroll's contentOffset.y to an Animated.Value, with useNativeDriver: true. The header then follows the scroll on the native side, with no JS per frame.
Why is transform better than width?
transform and opacity need no new layout, can run on the native driver, and cost less. width means layout every frame. It's the same rule as on the web, where transform is smoother than width.
Next lesson
Gestures on a phoneLevel: Intermediate
Frames can run without JS now; next, the same idea under a finger: gestures that follow it however busy JS is.