Upgrade to Pro — share decks privately, control downloads, hide ads and more …

React Native Bridges Architectures

React Native Bridges Architectures

This talk present the current React Native Bridge architecture, explaining its characteristics, how it works and its drawbacks.
It also talk about how the new future bridge architecture will look like

Sibelius Seraphini

August 31, 2018
Tweet

More Decks by Sibelius Seraphini

Other Decks in Education

Transcript

  1. Libraries or components that allow you to write native code

    (Objective C/Swift or Java) and integrate them with your React Native app. Also called Bridge Modules. What is a native module? 3
  2. - For when you need access to platform API -

    When you want to reuse code written in a native language - Using a third party library only available in native language - High performance, multi-threaded code (image processing, for example) Why use them? 4
  3. Use RN bridge library for ObjC/Java to export your module

    and expose it to JavaScript Import the native module as a library to your app and use methods, views and receive events Main Idea of a Bridge 5
  4. - React Native returns a single JSON that lists mutations

    to perform. - [["createView", attrs], ["manageChildren", ...]] How does it works? 7
  5. - shadow queue - where the layout happens - main

    thread - where UIKit/Android does it thing - Javascript thread - where your JS code is actually running - GCD queue - for each Native Module How it works? 8
  6. - Native Modules - expose native API without a UI

    - e.g.: package that read calendar events - Native UI Modules - expose a UI widget - e.g.: RNCamera component Types of Native Modules 11
  7. Why Bridge is hard - Need to implement in native

    language (know Java and Objective C) - You need to implement the same logic twice - Bridge can be slow to pass big amounts of data (like images as base64 strings) - Need to be familiar with other IDEs like XCode and Android Studio
  8. - asynchronous - hard to make sync APIs - serializable

    - unnecessary copying instead of directly sharing memory - batched - harder to call functions natively React Native Bridge Drawbacks 13
  9. - Change threading model: enable synchronously on JavaScript - Async

    Rendering - rendering priorities - Simplifying - Faster and more lightweight React Native Bridge Future 14
  10. - Shared memory owner: share between native and JavaScript -

    JSI - interop layer between JavaScript and native - Opt-in synchronous execution - UI responsiveness React Native Bridge Future 15
  11. I didn't mention 18 - How to really implement them

    (check this https://speakerdeck.com/jgfidelis/react-native-n ative-modules) - Deep dive on new native modules bridge structures