76
kevin o’neill email: [email protected] twitter: @kevinoneill

React Native

Embed Size (px)

Citation preview

Page 1: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

Page 2: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

building mobile applications that delight users is hard

Page 3: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

building mobile applications for multiple platforms

that delight users is harder

Page 4: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

choices

Page 5: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

native development

Page 6: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

platform feel raw performance

full platform integration

Page 7: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

the challenge ofnative development

Page 8: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

slow development cycles slow deployment cycles

multiple languagesmultiple api’s

Page 9: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

cross platform development

Page 10: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

quick development cycles quick deployment cycles

single languagesingle api*

Page 11: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

the challenge ofcross platform development

Page 12: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

poor performance poor Feel

lowest denominator

Page 13: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

and neither approach

Page 14: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

helps you manage the growing complexity of modern mobile

applications

Page 15: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

introducingreact native

Page 16: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

slow development cycles hot reload

Page 17: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

slow deployment cycles direct ota updates

Page 18: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

multiple languges es6/7 javaScript core

Page 19: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

multiple api’s 90% of the api’s are shared

between platforms

Page 20: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

poor performance native corevirtual dom

Page 21: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

poor feel native ui and interactions

Page 22: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

lowest denominator split between platforms where

distinction is required

Page 23: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

react native

Page 24: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

a native core with modern javascript

a functional ui and flexbox layout

Page 25: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

the ui is pure native not a UIWebView bridge

a native core

Page 26: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

utilises a ‘message bus’for communication between

application logic and the native ui

Page 27: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

creating your own native modules is trivial

Page 28: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

bridging modules@interface CalendarManager : NSObject <RCTBridgeModule> @end

@implementation CalendarManager RCT_EXPORT_MODULE()

RCT_EXPORT_METHOD( addEvent:(NSString *)name location:(NSString *)location) { RCTLogInfo(@"Pretending to create an event %@ at %@", name, location); } @end

Page 29: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

bridging modules

import { CalendarManager } from ‘NativeModules';

CalendarManager.addEvent(‘React Native Talk', 'NAB');

Page 30: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

bridging native views

@interface MapManager : RCTViewManager <MKMapViewDelegate> @end

@implementation MapManager RCT_EXPORT_MODULE() - (UIView *)view { return [[MKMapView alloc] init]; } @end

Page 31: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

bridging native views

import React from ‘react-native';

let { requireNativeComponent } = React;

export default requireNativeComponent(‘Map', null);

Page 32: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

bridging native views

import React from 'react-native';

let { requireNativeComponent } = React;

export default requireNativeComponent(‘Map', null);

Page 33: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

the majority of the time you wont be concerned with the bridge

Page 34: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

events- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {

MKCoordinateRegion region = mapView.region; NSDictionary *event = @{ @“center": { @"lat": @(region.center.latitude), @"long": @(region.center.longitude) }}; [self.bridge.eventDispatcher sendInputEventWithName:@"centerChanged" body:event];}

Page 35: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

eventsclass MapView extends React.Component { constructor() { this._onChange = this._onChange.bind(this); }

_onChange(event: Event) { if (!this.props.onCenterChange) { return; } this.props.onCenterChange(event.nativeEvent.center); } render() {

return <Map onChange={this._onChange} />; }

}

Page 36: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

es 6/7 modern javascript

Page 37: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

babel a javascript compiler

Page 38: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

es6• Arrow functions: <C onPress={() => this.setState({pressed: true})}• Block scoping: let greeting = 'hi';• Call spread: Math.max(...array);• Classes: class C extends React.Component { render() { return <View />; } }

• Constants: const answer = 42;• Destructuring: var {isActive, style} = this.props;• Modules: import React, { Component } from 'react-native';• Computed Properties: var key = 'abc'; var obj = {[key]: 10};• Object Consise Method: var obj = { method() { return 10; } };• Object Short Notation: var name = 'vjeux'; var obj = { name };• Rest Params: function(type, ...args) { }• Template Literals: var who = 'world'; var str = `Hello ${who}`;

Page 39: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

es7

• Object Spread: var extended = { ...obj, a: 10 };• Function Trailing Comma: function f(a, b, c,) { }• Async Functions: async function doStuffAsync() { const foo = await doOtherStuffAsync(); };

Page 40: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

jsx markup in javascript

Page 41: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

it’s clearer to work with markup than raw

javascript

Page 42: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

jsxrender() { const movie = this.props.movie; return ( <View style={styles.container}> <Text>{movie.title}</Text> <Text>{movie.year}</Text> <Image source={{uri: movie.posters.thumbnail}} /> </View> ); }

Page 43: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

isn’t mixing layout and logic bad

Page 44: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

other toolsflow, typescript, redux …

Page 45: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

define states, not transitionsfunctional ui

Page 46: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

describing transitions

Page 47: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

describing states

Page 48: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

the view hierarchy is recalculated for every state change

Page 49: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

the virtual dom

Page 50: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

describes the view hierarchy

Page 51: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

recalculated on state change

Page 52: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

differences used to patch the ui

Page 53: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

stacked views on steroids flexbox layout

Page 54: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

containers

Page 55: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

rows

Page 56: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

columns

Page 57: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

start

Page 58: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

end

Page 59: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

center

Page 60: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

space around

Page 61: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

space between

Page 62: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

wrapping

Page 63: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

proportional sizing

Page 64: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

plus content alignment, self alignment and more

Page 65: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

i liked flexBox so muchi created a swift version

Page 66: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

Page 67: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

Closing Thoughts

Page 68: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

react makes it easier to reason about application state

Page 69: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

it’s not a cure all

Page 70: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

it’s under active developmentand sometimes unstable

Page 71: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

facebook groups and pages are built on it

Page 72: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

it’s not an all or nothing proposition

Page 73: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

until now i’ve been a pure native developer

Page 74: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

it allows rapid iterationon your product ideas

Page 75: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

it’s a cornerstone technologyfor my new startup

Page 76: React Native

kevin o’neillemail: [email protected] twitter: @kevinoneill

Thank you Questions?