21
1 BUILDING APPS WITH REACT NATIVE @mthmulders [email protected]

BUILDING APPS WITH REACT NATIVE - Jfokus...BUILDING APPS WITH REACT NATIVE [email protected] @mthmulders 2 . 1 2 . 2. W . . . S W O R N S W O R D S W E D E 3 DEMO TIME! Getting

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: BUILDING APPS WITH REACT NATIVE - Jfokus...BUILDING APPS WITH REACT NATIVE maartenm@infosupport.com @mthmulders 2 . 1 2 . 2. W . . . S W O R N S W O R D S W E D E 3 DEMO TIME! Getting

1

BUILDING APPS WITHREACT NATIVE

@[email protected]

Page 2: BUILDING APPS WITH REACT NATIVE - Jfokus...BUILDING APPS WITH REACT NATIVE maartenm@infosupport.com @mthmulders 2 . 1 2 . 2. W . . . S W O R N S W O R D S W E D E 3 DEMO TIME! Getting

 

Page 3: BUILDING APPS WITH REACT NATIVE - Jfokus...BUILDING APPS WITH REACT NATIVE maartenm@infosupport.com @mthmulders 2 . 1 2 . 2. W . . . S W O R N S W O R D S W E D E 3 DEMO TIME! Getting

2 . 1

2 . 2

. W . . .

S W O R N

S W O R D

S W E D E

Page 4: BUILDING APPS WITH REACT NATIVE - Jfokus...BUILDING APPS WITH REACT NATIVE maartenm@infosupport.com @mthmulders 2 . 1 2 . 2. W . . . S W O R N S W O R D S W E D E 3 DEMO TIME! Getting

3

DEMO TIME!Getting started

Page 5: BUILDING APPS WITH REACT NATIVE - Jfokus...BUILDING APPS WITH REACT NATIVE maartenm@infosupport.com @mthmulders 2 . 1 2 . 2. W . . . S W O R N S W O R D S W E D E 3 DEMO TIME! Getting

4

BUT THERE'S...... Cordova/PhoneGap

HTML, JavaScript, CSSweb-app inside browser inside app

 ... Xamarin

C#includes Mono runtime

Page 6: BUILDING APPS WITH REACT NATIVE - Jfokus...BUILDING APPS WITH REACT NATIVE maartenm@infosupport.com @mthmulders 2 . 1 2 . 2. W . . . S W O R N S W O R D S W E D E 3 DEMO TIME! Getting

5 . 1

INTERNALSStartupExecutionRuntime

Page 7: BUILDING APPS WITH REACT NATIVE - Jfokus...BUILDING APPS WITH REACT NATIVE maartenm@infosupport.com @mthmulders 2 . 1 2 . 2. W . . . S W O R N S W O R D S W E D E 3 DEMO TIME! Getting

5 . 2

APPLICATION STARTUPApplication

Native Modules JavaScript VM JavaScript bundle

JSON configuration

Execute JavaScript

Page 8: BUILDING APPS WITH REACT NATIVE - Jfokus...BUILDING APPS WITH REACT NATIVE maartenm@infosupport.com @mthmulders 2 . 1 2 . 2. W . . . S W O R N S W O R D S W E D E 3 DEMO TIME! Getting

5 . 3

JAVASCRIPT EXECUTION

JavaScriptCore from WebKit (Safari)Available on iOS, packaged on AndroidExcept when debugging in Chrome → V8

Parse Generate AST Generate Bytecode Run Bytecode

Page 9: BUILDING APPS WITH REACT NATIVE - Jfokus...BUILDING APPS WITH REACT NATIVE maartenm@infosupport.com @mthmulders 2 . 1 2 . 2. W . . . S W O R N S W O R D S W E D E 3 DEMO TIME! Getting

5 . 4

PROGRAM FLOWBridge

Native Module

JavaScript execution

Shadow Views Layout Native Views

Render (screen)

UI Kit

User

Page 10: BUILDING APPS WITH REACT NATIVE - Jfokus...BUILDING APPS WITH REACT NATIVE maartenm@infosupport.com @mthmulders 2 . 1 2 . 2. W . . . S W O R N S W O R D S W E D E 3 DEMO TIME! Getting

6 . 1

BUILDING YOUR APPReactStylingState / Redux

Page 11: BUILDING APPS WITH REACT NATIVE - Jfokus...BUILDING APPS WITH REACT NATIVE maartenm@infosupport.com @mthmulders 2 . 1 2 . 2. W . . . S W O R N S W O R D S W E D E 3 DEMO TIME! Getting

6 . 2

REACTDeclarative UIComponent-based

Page 12: BUILDING APPS WITH REACT NATIVE - Jfokus...BUILDING APPS WITH REACT NATIVE maartenm@infosupport.com @mthmulders 2 . 1 2 . 2. W . . . S W O R N S W O R D S W E D E 3 DEMO TIME! Getting

6 . 3

COMPONENTSclass HelloMessage extends React.Component { render() { return <div>Hello { this.props.name }</div>; } }

class App extends React.Component { render() { return <HelloMessage name={ 'Jfokus' } />; } }

ReactDOM.render(<App />, document.getElementById("app"));

Page 13: BUILDING APPS WITH REACT NATIVE - Jfokus...BUILDING APPS WITH REACT NATIVE maartenm@infosupport.com @mthmulders 2 . 1 2 . 2. W . . . S W O R N S W O R D S W E D E 3 DEMO TIME! Getting

6 . 4

ES6 & JSXclass HelloMessage extends React.Component { render() { return <div>Hello { this.props.name }</div>; } }

var HelloMessage = React.createClass({ render: function() { return <div>Hello, { this.props.name }</div>; } });

var HelloMessage = React.createClass({ render: function() { return React.createElement('div', null, 'Hello ' + this.props.name); } });

Page 14: BUILDING APPS WITH REACT NATIVE - Jfokus...BUILDING APPS WITH REACT NATIVE maartenm@infosupport.com @mthmulders 2 . 1 2 . 2. W . . . S W O R N S W O R D S W E D E 3 DEMO TIME! Getting

6 . 5

STYLING YOUR APPNo browser, no CSS, so...?

import { StyleSheet, Text } from "react-native";

const styles = StyleSheet.create({ red: { color: "red" // or "#ff0000", or "rgb(255, 0, 0)" } });

class HelloMessage extends React.Component { render() { return <Text style={ styles.red }>...</Text>; } }

Page 15: BUILDING APPS WITH REACT NATIVE - Jfokus...BUILDING APPS WITH REACT NATIVE maartenm@infosupport.com @mthmulders 2 . 1 2 . 2. W . . . S W O R N S W O R D S W E D E 3 DEMO TIME! Getting

6 . 6

APPLICATION STATE

Item 1 Item 2 Item 3 Item ...

App

LoadingScreen

ListView

Should I pass my state down through all components?!

Page 16: BUILDING APPS WITH REACT NATIVE - Jfokus...BUILDING APPS WITH REACT NATIVE maartenm@infosupport.com @mthmulders 2 . 1 2 . 2. W . . . S W O R N S W O R D S W E D E 3 DEMO TIME! Getting

6 . 7

MEET REDUX!Core ideas:

1. State is single source of truth → no copies

2. State is read-only → state is mutated by emitting actions

3. Changes are made with pure functions → reducers take current state and action (+ params) → always return new objects

BTW, pure functions are easy to test :)

Page 17: BUILDING APPS WITH REACT NATIVE - Jfokus...BUILDING APPS WITH REACT NATIVE maartenm@infosupport.com @mthmulders 2 . 1 2 . 2. W . . . S W O R N S W O R D S W E D E 3 DEMO TIME! Getting

6 . 8

DEMOconst initialState = { todos: [] }; const reducer = (state = initialState, action) => { switch (action.type) { case 'ADD_TODO': const id = state.todos.length + 1; const todo = { title: action.title, complete: false, id }; } };

const store = createStore(reducer); store.dispatch({ type: 'ADD_TODO', title: 'Speak at Jfokus' }); console.log(store.getState());

Page 18: BUILDING APPS WITH REACT NATIVE - Jfokus...BUILDING APPS WITH REACT NATIVE maartenm@infosupport.com @mthmulders 2 . 1 2 . 2. W . . . S W O R N S W O R D S W E D E 3 DEMO TIME! Getting

6 . 9

REACT-REDUX: REACT <3 REDUXProvide Redux' store to your app

import { Provider } from 'react-redux'; const store = createStore(reducer);

<Provider store={ store }> <LoadingScreen /> </Provider>

Page 19: BUILDING APPS WITH REACT NATIVE - Jfokus...BUILDING APPS WITH REACT NATIVE maartenm@infosupport.com @mthmulders 2 . 1 2 . 2. W . . . S W O R N S W O R D S W E D E 3 DEMO TIME! Getting

6 . 10

REACT-REDUX: REACT <3 REDUXConnect components to Redux' store

import { Text } from 'react-native'; import { connect } from 'react-redux';

export const Counter = (props) => { return (<Text>There are { props.count } tasks</Text>); }

const mapStateToProps = (state) => { return { count: state.todos.length }; } const mapDispatchToProps = (dispatch) => { return { }; }

export default connect(mapStateToProps, mapDispatchToProps) (Counter);

Page 20: BUILDING APPS WITH REACT NATIVE - Jfokus...BUILDING APPS WITH REACT NATIVE maartenm@infosupport.com @mthmulders 2 . 1 2 . 2. W . . . S W O R N S W O R D S W E D E 3 DEMO TIME! Getting

7

DEMO TIME!

https://git.io/vMEuW

Page 21: BUILDING APPS WITH REACT NATIVE - Jfokus...BUILDING APPS WITH REACT NATIVE maartenm@infosupport.com @mthmulders 2 . 1 2 . 2. W . . . S W O R N S W O R D S W E D E 3 DEMO TIME! Getting

8

Q & A