mobile apps mit react-native - berlin expert...

47
Mobile Apps mit React-Native Manuel Mauky @manuel_mauky

Upload: others

Post on 04-Jun-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

Mobile Apps mit React-Native

Manuel Mauky@manuel_mauky

Page 2: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

Mobile Apps?

Page 3: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

Mobile Apps? - Welche Möglichkeiten existieren?

Native

AndroidiOS

Page 4: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

Mobile Apps? - Welche Möglichkeiten existieren?

Native

AndroidiOS

Web App

Single-Page-App im Browser

Page 5: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

Mobile Apps? - Welche Möglichkeiten existieren?

Native

AndroidiOS

Web App

Single-Page-App im Browser

HTML5 Hybrid

Web-App in native Wrapper/WebView

- Cordova- PhoneGap- Ionic

Page 6: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

Mobile Apps? - Welche Möglichkeiten existieren?

Native

AndroidiOS

Web App

Single-Page-App im Browser

HTML5 Hybrid

Web-App in native Wrapper/WebView

- Cordova- PhoneGap- Ionic

Andere Hybrid

- JavaFX

Page 7: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

Mobile Apps? - Welche Möglichkeiten existieren?

Native

AndroidiOS

Web App

Single-Page-App im Browser

HTML5 Hybrid

Web-App in native Wrapper/WebView

- Cordova- PhoneGap- Ionic

Andere Hybrid

- JavaFX

Native Cross-Plattform

- React-Native- NativeScript- Xamarin

Page 8: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

Vergleich mit HTML5-Cross-PlattformGemeinsamkeiten

- JavaScript- CSS*- natives Package (apk, ipa)- App Stores

Unterschiede

- kein HTML- keine WebView- React-Native rendert native Componenten

Page 9: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

OSOS

App

Vergleich mit HTML5-Cross-PlattformReact-Native

NativeJava/C++ JS VM

Bridge (C++/Java) App.js

AppWebView

index.html

app.jsapp.css

System APIs

System APIs

Hybrid App

Page 10: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

React-Native

React → Erstellung von UI-Komponenten (vor allem für Web)

React-Native → React für native Anwendungen zu nutzen

Entwickelt von Facebook seit 2013

OpenSource seit 2015

Page 11: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

React

Page 12: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

React DOMimport React from 'react'

class HelloWorld extends React.Component {render() {

return (<div>

<p>Hello {this.props.name}</p></div>

)}

}

// usage<HelloWorld name='Hugo' />

Page 13: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

React DOMimport React from 'react'

const HelloWorld = (props) => (<div>

<p>Hello {props.name}</p></div>

)

// usage<HelloWorld name='Hugo' />

Page 14: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

Compositionimport React from 'react'

const HelloWorld = (props) => (<div>

<p>Hello {props.name}</p></div>

)

const HelloList = (props) => (<ul>

<li><HelloWorld name='Hugo' /></li><li><HelloWorld name='Marlene' /></li><li><HelloWorld name='Luise' /></li>

</ul>)

Page 15: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

import React from 'react'

const HelloWorld = (props) => (<div>

<p>Hello {props.name}</p></div>

)

const HelloList = (props) => (<ul>

{ props.names.map(name => <li><HelloWorld name={name} /></li>) }</ul>

)

// usage<HelloList names={['Hugo', 'Marlene', 'Luise']} />

Page 16: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

import React from 'react'

const HelloList = (props) => {if(props.names.length === 0) {

return <p>Niemand da!</p>} else {

return <ul>{ props.names.map(name => (

<li><HelloWorld name={name} />

</li>)) }

</ul>}

}

// usage<HelloList names={['Hugo', 'Marlene', 'Luise']} />

Page 17: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

import React from 'react'

const HelloWorld = (props) => (<div>

<p>Hello {props.name}</p></div>

)

const HelloList = (props) => (<ul>

{ props.names.map(name => <li><HelloWorld name='Hugo' /></li>) }</ul>

)

// usage<HelloList names={['Hugo', 'Marlene', 'Luise']} />

Page 18: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

React-Native

Page 19: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

import React from 'react'import { View, Text, FlatList } from 'react-native'

const HelloWorld = (props) => (<View>

<Text>Hello {props.name}</Text></View>

)

const HelloList = (props) => (<FlatList

data={props.names}renderItem={({item}) => <HelloWorld name={item} />}

/>)

// usage<HelloList names={['Hugo', 'Marlene', 'Luise']} />

Page 20: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

"Write once, run anywhere"

"Learn once, write anywhere"

Page 21: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

KomponentenView

Text

TextInput

DatePicker

Switch

Slider

Image

Button

Modal

StatusBar

Picker

ListView

ScrollView

WebView

Page 22: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

APIsAccessibility

Alert

Clipboard

Geolocation

Animation

Network-Info

Storage

Camera

Share

Timers

Vibration

Keyboard

Page 23: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

Apps Bauen

Page 24: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

Apps bauenimport { Text, View, AppRegistry } from 'react-native'

const App = (props) => (<View>

<Text>Hallo Welt></View>

)

AppRegistry.registerComponent('myapp', () => App)

Page 25: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

Apps bauenimport { Text, View, AppRegistry } from 'react-native'

const App = (props) => (<View>

<Text>Hallo Welt></View>

)

AppRegistry.registerComponent('myapp', () => App);

Page 26: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

Styling

Page 27: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

Stylingconst styles = StyleSheet.create({

container: {height: 500,backgroundColor: 'coral'

},text: {

fontSize: 40,color: '#fff8dc'

}})

const App = (props) => (<View style={styles.container}>

<Text style={styles.text}>Hallo Welt></View>

);

Page 28: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

Stylingconst styles = StyleSheet.create({

container: {height: 500,backgroundColor: 'coral'

},text: {

fontSize: 40,color: '#fff8dc'

}})

const App = (props) => (<View style={styles.container}>

<Text style={styles.text}>Hallo Welt></View>

);

Page 29: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

Layout

Page 30: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

Layout? FlexBox!const styles = StyleSheet.create({

container: {flex: 1,justifyContent: 'center',backgroundColor: 'coral'

},text: {

fontSize: 40,color: '#fff8dc'

}})

const App = (props) => (<View style={styles.container}>

<Text style={styles.text}>Hallo Welt></View>

);

Page 31: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

Layout? FlexBox!const styles = StyleSheet.create({

container: {flex: 1,justifyContent: 'center',backgroundColor: 'coral'

},text: {

fontSize: 40,color: '#fff8dc'

}})

const App = (props) => (<View style={styles.container}>

<Text style={styles.text}>Hallo Welt></View>

);

Page 32: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

Layout? FlexBox!const styles = StyleSheet.create({

container: {flex: 1,justifyContent: 'center',alignItems: 'center',backgroundColor: 'coral'

},text: {

fontSize: 40,color: '#fff8dc'

}})

const App = (props) => (<View style={styles.container}>

<Text style={styles.text}>Hallo Welt></View>

);

Page 33: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

Plattform-Spezifische Komponenten

Page 34: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

Plattformspezifische Komponentenimport { Text, Platform } from 'react-native'

const HelloWorld = (props) => {let greeting;

if(Platform.OS === 'ios') {greeting = 'Welcome on iOS';

} else {greeting = 'Hi Android user';

}

return <Text>{greeting}</Text>}

Page 35: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

Plattformspezifische Komponentenimport { Text, Platform } fron 'react-native'

const HelloWorld = (props) => {let greeting;

if(Platform.OS === 'ios') {greeting = 'Welcome on iOS';

} else {greeting = 'Hi Android user';

}

return <Text>{greeting}</Text>}

Page 36: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

Plattformspezifische Komponentenimport { Text, Platform } fron 'react-native'

const HelloWorld = (props) => {let greeting;

if(Platform.OS === 'ios') {greeting = 'Welcome on iOS';

} else {greeting = 'Hi Android user';

}

return <Text>{greeting}</Text>}

Welcome on iOS

Page 37: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

// HelloWorld.ios.jsconst HelloWorld = (props) => (

<Text>Welcome on iOS</Text>)

// HelloWorld.android.jsconst HelloWorld = (props) => (

<Text>Hi Android user</Text>)

// SomeOtherComponent.jsimport HelloWorld from 'HelloWorld'

const SomeOtherComponent = (props) => (<View>

<HelloWorld /></View>

)

Welcome on iOS

Page 38: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

Netzwerk- Fetch API (Spec in Progress)

fetch('https://blubba.io/api')

.then((response) => response.json())

.then((json) => {

console.log("data:", json)

});

Page 39: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

Demo

Page 40: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

Fazit

Page 41: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

PlattformenReact DOM: Browser

React-Native:

- Android, iOS offiziell Supported- Windows 10 support von Microsoft- Windows 7-8 durch Community- MacOS durch Community- Ubuntu durch Canonical :-(

React VR

Page 42: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

Vorteile React-Native- Eine Art zu Programmieren auf mehreren Plattformen- React + Redux- OOP → Funktional- Dev-Tools

- Time-Travel- Live-Reloading

- Aktive Community- Schnelle Ergebnisse auf verschiedenen Plattformen

Page 43: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

Vergleich mit Native- Performance

- prinzipiell vergleichbar- mehr Tuning-Möglichkeiten bei Native

- Mehr Componenten/APIs bei Native- Näher an der Hardware- Dev-Tools (GUI-Builder)

Page 44: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

Vergleich mit HTML5-Cross-Platform- unterstützte Plattformen

- React-Native: Android + iOS- Cordova: Android, iOS, Windows Phone, BlackBerry, Symbian, …

- Performance- Look and Feel

Page 45: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

Vergleich mit Browser-Single-Page-Apps- kein AppStore (Vorteil und Nachteil)- Auffindbar über Web- unterstützte Plattformen- Performance

Page 46: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

- Play-Store- Code:

https://github.com/facebook/react-native/tree/master/Examples/UIExplorer

Page 47: Mobile Apps mit React-Native - Berlin Expert Daysbed-con.org/2017/files/slides/Mauky-React_Native.pdf · Mobile Apps? - Welche Möglichkeiten existieren? Native Android iOS Web App

Fragen?@manuel_mauky

github.com/lestardwww.lestard.eu