Upgrade to Pro — share decks privately, control downloads, hide ads and more …

React Native — Webnesday #9

Robert Vogt
November 09, 2016

React Native — Webnesday #9

Slides for my talk about React Native at Webnesday #9 in St. Gallen.

Robert Vogt

November 09, 2016
Tweet

More Decks by Robert Vogt

Other Decks in Programming

Transcript

  1. $str = '<ul>'; foreach ($talks as $talk) { $str +=

    '<li>' . $talk->name . '</ li>'; } $str += '</ul>'; 1. Facebook in 2004 (PHP)
  2. «Welp, I’m going to take XHP to the browser within

    six months.» — Jordan Walke, Facebook / ReactJS
  3. var content = ( <TalkList>{talks.map(talk => <Talk talk={talk} /> )}

    </TalkList> ); 4. Facebook in 2013 (ReactJS)
  4. function f(name) { var div = document.createElement('div'); var p =

    document.createElement('p'); p.textContent = 'Hello ' + name ? name : 'World'; div.appendChild(p); return div; } 
 var node = f('Webnesday'); document.getElementById('my- app').replaceWith(node);
  5. $(document).on('message.new', () => { let $count = $('.notifications__count'); let currentCount

    = parseInt($count.text(), 10); $count.text(++currentCount); }); 2. jQuery (Imperative)
  6. const state = { unread: 1, messages: [{ id: 43,

    body: 'Hallo!', sender: 'Alice' }, { id: 42, body: 'Hoi :)', sender: 'Bob' }] }; 1. ReactJS (Declarative)
  7. class TalkList extends React.Component { render () { return (

    <ul className='talk-list'> {props.messages.map((message) => ( <li>{message.sender} says: {message.body}</li> )} </ul> ); } }
 <TalkList messages={state.message} /> 2. ReactJS (Declarative)
  8. class Counter extends React.Component { render () { const {

    count } = this.props; return ( <span className='counter'>{count}</span> ); } }
 <Counter count={state.unread} /> 3. ReactJS (Declarative)
  9. const state = { unread: 2, messages: [{ id: 44,

    body: 'Wie gehts!', sender: 'Alice' }, { id: 43, body: 'Hallo!', sender: Alice' }] }; 4. ReactJS (Declarative)
  10. class Hello extends React.Component { constructor(props) { super(props); this.state =

    { name: 'World' }; } render() { return ( <div className="hello"> <input ref={(c) => this._input = c} type="text" placeholder="Your Name" onChange={() => this.setState({ name: this._input.value })} /> <p>Hello {this.state.name}!</p> </div> ); } }
  11. class Hello extends React.Component { constructor(props) { super(props); this.state =

    { name: 'World' }; } render() { return ( <View> <TextInput ref={(c) => this._input = c} placeholder="Your Name" onChange={() => this.setState({ name: this._input.value })} />
 <Text>Hello {this.state.name}!</Text> </View> ); } }
  12. Components ActivityIndicator Button DatePickerIOS DrawerLayoutAndroid Image ListView MapView Modal Navigator

    Picker ProgressBarAndroid ProgressViewIOS RefreshControl ScrollView Slider SnapshotViewIOS StatusBar Switch TabBarIOS Text TextInput TouchableHighlight TouchableNativeFeedback TouchableOpacity TouchableWithoutFeedback View WebView APIS Alert Animated AppState AsyncStorage BackAndroid CameraRoll Clipboard Dimensions Geolocation ImageEditor ImageStore Keyboard Linking NetInfo PanResponder PushNotificationIOS Settings StyleSheet ToastAndroid Vibration
  13. React Native Community Quality code from the React Native Community

    github.com/react-native-community react-native-svg react-native-elements react-native-blur react-native-tab-view react-native-video react-native-navbar react-native-side-menu
  14. JS Runtime React Native
 JS API Custom App Code Android

    SDK Custom View Manager iOS SDK RN Bridge
  15. Native Bridge JavaScript 1 2 3 4 5 6 8

    7 Event (touch, timer, networks, …) Collect data and notify JS Serialized payload Process event Call native methods Update UI if needed Process commands Serialized response
  16. $ brew install node $ brew install watchman $ npm

    install -g react-native Xcode AND/OR Gradle + Android Emulator
  17. ! A Word Of Warning Fun on OS X macOS,

    not so much on Linux / Windows.
  18. .babelrc android index.android.j s index.ios.js ios node_modules package.json src !""

    app.js $ react-native init WebnesdayApp $ cd WebnesdayApp $ react-native run-ios