Ah, React Native animations. Long-considered to be one of the pain points of React Native development, due to their steep learning curve and being packed with potentially performance-crushing pitfalls, creating delightful animations and gesture-based interactions has been hard. But why so tricky? The answer lies in React Native’s architecture, namely with something called the bridge. In order to understand why, let’s have a brief look at React Native’s architecture to find out more.

Architecture

In order to provide close-to-native performance, React Native uses a dual-thread architecture – a JS thread, which runs your React Native code, and a native UI thread. Your React Native components are effectively specifications for native UI components – layout is taken care of by a Flexbox engine – you in theory get Native UI performance (in reality, your mileage may vary) but get to use your favourite UI framework, React, with some caveats. These two threads communicate via a glorified pipe with some extra features known as the bridge. This bridge is fully asynchronous, and lets one call to native code from JS, also asynchronously. The official React Native docs explain in more detail.

The bridge is often the performance bottleneck in React Native projects, as communication is orders of magnitude slower than most other operations (especially on Android). This isn’t because it’s poorly written, it’s just the nature of the beast. In any case, minimising over-the-bridge communication is a good general strategy for achieving native-like performance in any app.

#react-native #code #animation

Animations in React Native Just Got a Whole Lot Easier
1.60 GEEK