Slide 1

Slide 1 text

React Native Bridges Sibelius Seraphini

Slide 2

Slide 2 text

Sibelius Seraphini @sibelius @sseraphini 2

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

- 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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

- asynchronous - serializable - batched Bridge Architecture 6

Slide 7

Slide 7 text

- React Native returns a single JSON that lists mutations to perform. - [["createView", attrs], ["manageChildren", ...]] How does it works? 7

Slide 8

Slide 8 text

- 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

Slide 9

Slide 9 text

Bridge initialization dependency graph 9

Slide 10

Slide 10 text

Bridge call cycle 10

Slide 11

Slide 11 text

- 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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

- 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

Slide 14

Slide 14 text

- Change threading model: enable synchronously on JavaScript - Async Rendering - rendering priorities - Simplifying - Faster and more lightweight React Native Bridge Future 14

Slide 15

Slide 15 text

- 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

Slide 16

Slide 16 text

Resources 16 https://github.com/prscX/awesome-react-native -native-modules https://setemasters.imasters.com.br/conversas /is-react-native-native/

Slide 17

Slide 17 text

Resources 17 - https://facebook.github.io/react-native/docs/nati ve-modules-ios - http://facebook.github.io/react-native/blog/2018 /06/14/state-of-react-native-2018 - https://github.com/react-native-community/disc ussions-and-proposals/issues/4

Slide 18

Slide 18 text

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