introduction to react native

37
React Native introduction 1

Upload: polidea

Post on 14-Jan-2017

615 views

Category:

Mobile


0 download

TRANSCRIPT

Page 1: Introduction to React Native

React Nativeintroduction

1

Page 2: Introduction to React Native

About the author

● CTO @ Polidea

● Founder of Mobile Warsaw

● Founder and organizer of mceconf.com

2

Page 3: Introduction to React Native

● not a Hybrid App framework

● no HTML/DOM, CSS*

● no cross-platform app tool

● no application architecture framework

● no, you cannot use jquery plugins with it*

What RN is not

3

Page 4: Introduction to React Native

A JAVASCRIPT LIBRARY FOR BUILDING USER INTERFACES

What RN is

Atwood's Law: any application that can be written in JavaScript, will eventually be written in JavaScript.

4

Page 5: Introduction to React Native

● native UI components● fully asynchronous UI● no two-way data-binding● no application architecture lock-in● great for modern patterns

○ CQRS (Domain Driven Design and Event Sourcing)○ Flux (Facebook pattern)

No architecture lock-in

5

Page 6: Introduction to React Native

Components - fundamental building blocks

● state machine

● properties

● render method (JSX)

● flexbox css-like style

● composable

6

Page 7: Introduction to React Native

Component demo

7

Page 8: Introduction to React Native

Rethink established best practicesTM

Component Example

8

Page 9: Introduction to React Native

Everything* is javascript

● code is javascript

● styles are … javascript

● views are … javascript

● layout calculation is … javascript

9

Page 10: Introduction to React Native

We all love Javascript

10

Page 11: Introduction to React Native

JSX example

var app = <Nav color="blue"> <Profile>click</Profile> </Nav>

var Nav, Profile;var app = React.createElement( Nav, {color:"blue"}, React.createElement(Profile, null, "click"));

11

Page 12: Introduction to React Native

Styles example

var styles = StyleSheet.create({

base: {

width: 38,

height: 38,

},

bckg: {

backgroundColor: '#222222',

},

active: {

borderWidth: 2,

borderColor: '#00ff00',

},

});

12

<Text style={styles.base} />

<View style={styles.bckg} />

<View style={[styles.base, styles.bckg]} />

<View style={[styles.base,

this.state.active && styles.active]} />

Page 13: Introduction to React Native

Not your grand-father’s javascript

● use ‘strict’

● Runtime: JavascriptCore/V8

● Node 4.0.0 : Node.js + io.js converged

● (some) ES6 + ES7: Babel transpiler

● @flow - compile time - static type check

13

Page 14: Introduction to React Native

Why react is different?

14

Page 15: Introduction to React Native

Application demo

15

Page 16: Introduction to React Native

States and Virtual View Hierarchy

Component

StateYour code

Render(in javascript)

View

Virtual View Hierarchy Javascript objects

Image

Image

Text

React

Build native views(native code)

16

Page 17: Introduction to React Native

State changes

Component

State: {}

Component

State: {workshops: {...} }Update State

Reconciliation

Incremental changesAnimations

Javascript

Native code

17

Page 18: Introduction to React Native

Incremental updates / animations

Update

Create

18

Page 19: Introduction to React Native

Is react fast (enough)?

19

Page 20: Introduction to React Native

Native/Javascript bridge

● Javascript runs in non-UI thread● Asynchronous, serializable communication● Batching requests● Lots of optimisations● More potential optimisations in the future● Flexible threading model

20

Page 21: Introduction to React Native

Animations

● LayoutAnimations - simple

● Animated - fine grained control ○ Value animations still in javascript

○ Will be native soon

○ Declarative

21

Page 22: Introduction to React Native

Animation example

22

Page 23: Introduction to React Native

Developers first

23

Page 24: Introduction to React Native

Integration with native code

● Native APIs: iOS/Android

● Native UI components: iOS/Android

● Direct Properties access: iOS/Android (?)

● Embed RN view in Native app: iOS for now

24

Page 25: Introduction to React Native

● Intellij Idea/Webstorm with JSX Harmony

● Live Reloads

● Support for debugging via Chrome tools

● React Chrome extension

● Modify code in debugger

Developer’s toolchain - web-developer’s like

25

Page 26: Introduction to React Native

Developer’s toolchain goodies

● Fast packager● Verbose error diagnostic● Element Inspections● Profiling● JS Tests● Integration tests and Snapshot tests (iOS for now)● UIExplorer

26

Page 27: Introduction to React Native

Deployment options

27

Page 28: Introduction to React Native

Internal Architecture

28

Page 29: Introduction to React Native

Standalone app

29

Page 30: Introduction to React Native

Development

30

Page 31: Introduction to React Native

Debugging

31

Page 32: Introduction to React Native

Remote server

32

Page 33: Introduction to React Native

Live AppStore application update - AppHub.io (iOS for now)

33

Page 34: Introduction to React Native

Facebook goals (what they told)

● Learn once - write anywhere

● No “cross-platform app framework”

● Less complex apps with React

34

Page 35: Introduction to React Native

● A lot of common code shared

● Reuse of existing libraries

● Built-in cross-platform support (soon)

● Dynamic app updates (A/B testing)

Facebook achievements

35

Page 36: Introduction to React Native

Is it ready yet?

● Still changing fast● Some small issues with performance● Needs verification with big application● (but Facebook made AdsManager)● Some components are beta● A number of community components● Slowly growing community ● “Distributed” documentation

36