Using Native Driver for Animations

When working with animations in React Native, it is easy to run into performance issues, especially if your app involves complex animations.

The Animated API was designed with a very important constraint in mind: it is serialisable. This means we can send everything about the animation to the native layer before it has even started and allows native code to perform the animation on the UI thread without having to go through the bridge on every frame.

Now we are talking!

It is very useful because once the animation has started, the JS thread can be blocked and the animation will still run smoothly.

When creating an Animation in React Native, you could create an Animated.Value and change this value to update some transforms in your UI components. Or you may also update an Animated value by connecting it to an event of a View using Animated.event .

However, most of the work happens on the JavaScript thread. If it is blocked, the animation will skip frames. It also needs to go from the JavaScript to Native layer on every frame to update native views.

What the native driver does is move all of these steps to native.

Since Animated produces a graph of animated nodes, it can be serialized and sent to native only once when the animation starts, eliminating the need to callback into the JS thread; the native code can take care of updating the views directly on the UI thread on every frame.

How to embed this native driver in your app is covered in the coming section.