Slide 1

Slide 1 text

Developing React Native Upon Native App Tomoak Imai @React Native Portland 7/20/2017

Slide 2

Slide 2 text

Hi I’m Tomo Mobile Developer (Android, ReactNative, iOS) Joined Mercari, Inc. 2014 twitter: @tomoaki_imai github: tomoima525

Slide 3

Slide 3 text

Can you tell the difference between Native & React Native?

Slide 4

Slide 4 text

Native + React Native Hybrid App

Slide 5

Slide 5 text

Native + React Native Hybrid App Native (TL, SearchBar, NavBar) React Native React Native React Native

Slide 6

Slide 6 text

Native + React Native Hybrid App /BUJWFTDSFFOT 3FBDU/BUJWFTDSFFOT 5JNF-JOF -JTUJOH $BNFSB (BMMFSZ $IFDLPVU *UFN%FUBJM %FFQMJOL8FC 4FUUJOHT &EJU 1SPpMF *OCPY $IBU 'PMMPXMJTU )BTBOJNBUJPO .VMUJUISFBEFEQSPDFTT 6TFT04'SBNFXPSL 4UBUJDQBHFT .PSFGBODZTDSFFOT

Slide 7

Slide 7 text

Developing Hybrid App is not simple! - How to Bridge data between React Native & Native - Using Native thru React Native, vice versa - Developing/Testing React Native upon Native App • Need to consider more things compared to React Native App

Slide 8

Slide 8 text

Agenda - Hybrid App Architecture and Key Components - Developing/Testing Flow for Hybrid App - How the team changed by developing Hybrid App

Slide 9

Slide 9 text

Hybrid App Architecture and Key Components

Slide 10

Slide 10 text

3FBDU'SBHNFOU 3FBDU3PPU7JFX Architecture in a nutshell 3FBDU/BUJWF 3FBDU*OTUBODF.BOBHFS /BUJWF .PEVMFT 0UIFS "DUJWJUJFT 3FBDU 4FSWJDF &WFOU )PPL 3FBDU 3FQPTJUPSZ JS bundle file React Native Native Framework Bridge

Slide 11

Slide 11 text

3FBDU'SBHNFOU 3FBDU3PPU7JFX Architecture in a nutshell 3FBDU/BUJWF 3FBDU*OTUBODF.BOBHFS /BUJWF .PEVMFT 0UIFS "DUJWJUJFT 3FBDU 4FSWJDF &WFOU )PPL 3FBDU 3FQPTJUPSZ JS bundle file React Native Native Framework Bridge

Slide 12

Slide 12 text

React Service & React Repository • React Service is a factory class that creates React Instance Manager • Also checks updates on JS Bundle • React Repository is where JS Bundle file is stored 3FBDU 4FSWJDF 3FBDU 3FQPTJUPSZ Load Bundle on memory from Asset directory 3FBDU*OTUBODF .BOBHFS Checks update on server Bundle from Local server (for development usage)

Slide 13

Slide 13 text

3FBDU'SBHNFOU 3FBDU3PPU7JFX Architecture in a nutshell 3FBDU/BUJWF 3FBDU*OTUBODF.BOBHFS /BUJWF .PEVMFT 0UIFS "DUJWJUJFT 3FBDU 4FSWJDF &WFOU )PPL 3FBDU 3FQPTJUPSZ JS bundle file React Native Native Framework Bridge

Slide 14

Slide 14 text

React Fragment • Handles which React Native Screen to open

Slide 15

Slide 15 text

React Fragment scene = “INBOX” USER_ID = “xxxx” HashMap data = new HashMap<>(1);
 data.put(USER_ID, userId);
 ReactFragment inboxContent = ReactFragment.newInstance(INBOX, data); • Handles which React Native Screen to open HomeActivity.java

Slide 16

Slide 16 text

React Fragment scene = “INBOX” USER_ID = “xxxx” HashMap data = new HashMap<>(1);
 data.put(USER_ID, userId);
 ReactFragment inboxContent = ReactFragment.newInstance(INBOX, data); HashMap params = getArguments().getSerializable(DATA); 
 Bundle bundle = new Bundle();
 bundle.putString( ”initialScene”, getArguments().getSerializable(SCENE));
 bundle.putSerializable(React.Param.DATA, data); 
 reactView.startReactApplication( reactManager, ReactService.MAIN_MODULE, bundle); • Handles which React Native Screen to open HomeActivity.java ReactFragment.java

Slide 17

Slide 17 text

React Fragment • Handles which React Native Screen to open class InboxScene extends React.Component { getChildContext() { if (this.props.user_id) { return { data: { user_id: this.props.user_id } }; } } … import * as scenes from './scenes'; const RouterWithRedux = connect()(Router); const initialSceneProps = { initial: true }; const Scenes = (props, context) => { // Setup all scenes _.map(scenes, (component, name) => ( ))} ;

Slide 18

Slide 18 text

3FBDU'SBHNFOU 3FBDU3PPU7JFX Architecture in a nutshell 3FBDU/BUJWF 3FBDU*OTUBODF.BOBHFS /BUJWF .PEVMFT 0UIFS "DUJWJUJFT 3FBDU 4FSWJDF &WFOU )PPL 3FBDU 3FQPTJUPSZ JS bundle file React Native Native Framework Bridge

Slide 19

Slide 19 text

Event Hook Module • Native Module that pass events/data from React Native to Native import { NativeModules } from 'react-native'; export const openActivity = (name, data = null) => { NativeModules.EventHook.sendEvent('openActivity', { name,data}); };

Slide 20

Slide 20 text

class ReactEventHookModule extends ReactContextBaseJavaModule {
 ReactEventHooks hooks;
 @ReactMethod
 public void sendEvent(String name, @Nullable ReadableMap data) {
 // receive parameters from react module
 hooks.getEventProcessor().onNext(new ReactEvent(name, data));
 }
 } Event Hook Module • Native Module that pass events/data from React Native to Native import { NativeModules } from 'react-native'; export const openActivity = (name, data = null) => { NativeModules.EventHook.sendEvent('openActivity', { name,data}); }; // ReactFragment.java public boolean handleEvent(ReactEvent reactEvent) {
 switch (reactEvent.getName()) {
 case ”openActivity”:
 openActivity(reactEvent);
 break;
 ….

Slide 21

Slide 21 text

Event Hook Module &WFOUXFTFOUGSPN3FBDU/BUJWF /BUJWF#BDL UPDMPTF3FBDU/BUJWF4DSFFO 0QFOOFX"DUJWJUZ7JFX$POUSPMMFS -PH&WFOU&SSPS$SBTI &ODSZQUJPO

Slide 22

Slide 22 text

Developing/Testing Flow for Hybrid App

Slide 23

Slide 23 text

Code Coverage Error Reporting Chat Ops Release Testing Notification Crash Report (thru Native) Upload Push

Slide 24

Slide 24 text

Chat Ops Release Testing Notification Code Coverage Error Reporting Upload Push Crash Report (thru Native)

Slide 25

Slide 25 text

Uploading to GCS • All Pull Requests will be deployed to GCS from CI

Slide 26

Slide 26 text

Testing from device • Download JS Bundle file from GCS • JS Bundle can be selected with Pull Request # on Github • Super easy to test with an actual device!

Slide 27

Slide 27 text

Chat Ops Release Testing Notification Code Coverage Error Reporting Upload Push Crash Report (thru Native)

Slide 28

Slide 28 text

Release Automation • Deployment to Production is done from Slack gsutil cp -a 4.1.2/* release/

Slide 29

Slide 29 text

How the development changed?

Slide 30

Slide 30 text

Code faster, Deploy faster! • All engineer can contribute to mobile app • Over The Air update every week When All tasks are Native Native + React Native Frontend Engineer Server Engineer 2 Native Engineers

Slide 31

Slide 31 text

Team members are becoming full stack mobile engineers

Slide 32

Slide 32 text

React Native experience for Android Developer Hard to find error in JSX (it won’t show in Debugger) No Type or Null check (started to introduce Flow) Clean Architecture. Thanks to Redux and Atomic design! Less code with ES6 Live reloading!!