React Native Gestures & Animations: you only have 16ms to render everything

React Native Gestures & Animations: you only have 16ms to render everything

The default Gesture and Animation APIs from React Native have some small declarative parts but they are mostly imperative: in most cases, they rely on communication between the JS and Native thread. This communication (aka “crossing the RN bridge”) takes time and there are no guarantees that a frame can be rendered in time, especially on small Android devices. On top of that, the JS thread is often busy with other tasks such as processing REST API calls for instance. In such a scenario, there won’t be any possibilities to render each frame in time.

In the code snippet below, we grad an object around the screen using PanResponder and Animated. Because these APIs rely on communication between the JS and the UI thread, frames will be drop if the JS thread gets busy and/or the device has limited computing powers.

The default APIs for gestures and animations in React Native require communication between the JS and the UI thread. In that context, there are no guarantees that an animation frame can be rendered within 16ms.

To overcome this challenge, Krzysztof Magiera, father of native gestures and animations in React Native, has published two libraries that will enable us to declare all gestures and animations beforehand on the UI thread: react-native-gesture-handler and react-native-reanimated. As a result, even if the JavaScript thread is continuously busy, the gestures and animations will still work seamlessly even on low-grade Android devices. Below is the exact same component rewritten with Gesture Handler and Reanimated: the JS thread is not used while running the gesture and animation.

No alt text provided for this image

Learn Declarative Gestures and Animations

Because of the declarative nature of Gesture Handler and Reanimated, the barrier to entry with these libraries is high. I started a YouTube series where I use these libraries to implement user experiences from apps that people know and love.

While the examples can YouTube can be sometimes complex, I released a course on the fundamental of Gesture Handler and Reanimated. My goal with this course is to provide you will all the tools and knowledge necessary in order to build butter-smooth gestures and animations that run at 60 fps even on low-grade Android devices.

No alt text provided for this image

We start by building simple transitions and then learn to harness the power of timing and physics-based animations, and more importantly how they integrate with gestures in order to provide professional-grade user-experiences. This course will be updated every month with new lessons as well as premium React Native starter kits.

Happy Hacking ??



Chris Lojniewski

Next.js Architect | CEO @ Pagepro

5 年

Good stuff, thanks for sharing. Performance of animations is the important topic in RN.?

回复

要查看或添加评论,请登录

William Candillon的更多文章

  • "Can it be done in React Native?"?-?a case for declarative gestures and animations

    "Can it be done in React Native?"?-?a case for declarative gestures and animations

    Not long after starting React Native development, I started to look at the apps on my phone in a very different way…

  • Building a Product Live on YouTube

    Building a Product Live on YouTube

    Recently, I created a premium iOS and Android starter kit named Elements. The design is from Sketch Elements and the…

  • React Native Do with Firebase Integration

    React Native Do with Firebase Integration

    Since its release, the React Native Do starter kit has gained substantial traction and it was time to provide new…

  • Responsive UIs in React Native

    Responsive UIs in React Native

    Recently, I published a premium starter kit for RN named React Native DO. Like many React Native apps on the market…

  • The 80/20 of React Native

    The 80/20 of React Native

    When building a React Native app, what twenty percent of your effort brings eighty percent of the result? After…

  • Building a Fitness App with React Native

    Building a Fitness App with React Native

    I am an avid user of apps like Freeletics and Headspace which target the fitness of the body and mind. These apps have…

  • React Native Push Notifications with Firebase

    React Native Push Notifications with Firebase

    Last week, Swizec Teller wrote an fantastic tutorial on adding push notifications to your React Native app using Cloud…

    1 条评论
  • Writing Cloud Functions with Typescript

    Writing Cloud Functions with Typescript

    Serverless architectures are awesome and I recently started to use Cloud Functions (via Firebase). Immediately, I…

    1 条评论
  • Firebase Schema Evolution

    Firebase Schema Evolution

    Schema evolution is a natural part of your application lifecycle. Firebase is my go-to backend for web and mobile…

  • Image Pipeline with React Native ListView

    Image Pipeline with React Native ListView

    In mobile apps, scrolling through a list of images is a very common use case for which users have high expectations. In…

社区洞察

其他会员也浏览了