SlideShare a Scribd company logo
React-Native: Introduction
Ilya Ivanov
Mobile Team Lead at Payoneer Team
Ciklum
static.ila@gmail.com
skype: innerself89
About me
• 1.5 years in react-native
• 3 years in web react.js
• 3 years in C#/.NET
What to expect
• React-Native in context
• Give you a vision of React-Native
• Help you avoid silly mistakes I did
when started
Agenda
• Ways to create mobile UI
• React.js in 5 minutes
• React-Native key concepts
• How React-Native works
• Advanced concepts
• React-Native pitfalls
Ways to create mobile UI
1. Native application (Objective-C/Java)
2. Website running within mobile browser
3. Hybrid application (HTML/JS/CSS in WebView)
MountainRoad
Hybrid
Cyclo-cross Cross-country
Types of bikes
React Native: Introduction
Ways to create mobile apps summary
• React-Native and NativeScript are new ways to create native apps
• Each approach is a balance between UX and development speed
Agenda
• Ways to create mobile UI
• React.js in 5 minutes
• React-Native key concepts
• How React-Native works
• Advanced concepts
• React-Native pitfalls
React.js in 5 minutes
• Declarative components
• Virtual DOM
• One-way data binding
Declarative components
import React, {Component} from 'react';
class App extends Component {
render() {
return (
<div>
<Title/>
<form>
<div>
<label>Email address</label>
<input type="text"/>
</div>
<br/>
<input type="button" value="Submit"/>
</form>
</div>
);
}
}
Title component
const Title = () =>
<h1>Sign me up!</h1>;
Virtual DOM
div
h1 form
div
label
input
br input
div
Browser DOM
div
h1 form
div
label
input
br input
div
DiffPatch
react-dom
react
One way data binding
Event loop
Handle
Event
Update
state
Re-render
to Virtual
DOM
Reconcile
Browser
DOM
One way data binding
class App extends Component {
state = {};
render() {
return (
<div>
{
this.state.submitted &&
<span>Thanks for submitting your email!</span>
}
<br/>
<input type="button"
value="Submit"
onClick={() => this.setState({submitted: true})}/>
</div>
);
}
}
React.js summary
• Declarative components
• Return virtual DOM elements
• Virtual DOM
• Abstracts away browser’s DOM
• Change DOM via patches
• One-way data binding
• Unidirectional data flow
• Triggered on explicit state changes (via setState call)
Agenda
• Ways to create mobile UI
• React.js in 5 minutes
• React-Native key concepts
• How React-Native works
• Advanced concepts
• React-Native pitfalls
React-Native key concepts
• Ways to bootstrap
• Primitives
• Styling
• Platform-specific code
Bootstrapping your application
react-native init MyApplication
Pros:
• Can use custom native code
• Stable in terms of dev experience
create-react-native-app MyApplication
Pros:
• No need to install Android Studio and Xcode
• Can publish your apps
• You can always eject
Initial app
class App extends Component {
render() {
return (
<View style={styles.container}>
<Text>
Welcome to React Native!
</Text>
</View>
);
}
}
Primitives
• View – fundamental component for building a UI. Supports layout
with flexbox.
• Similar to div
• Text – all text should be wrapped into Text component.
• Similar to span
• TouchableOpacity – component to handle user press.
• Somewhat similar to button
class App extends Component {
state = {
count: 0,
};
increment = () =>
this.setState({count: this.state.count + 1});
render() {
return (
<View>
<TouchableOpacity
onPress={this.increment}
>
<Text
{this.state.count}
</Text>
</TouchableOpacity>
</View>
);
}
}
Styling and flexbox
<View style={styles.container}>
<View style={styles.box}/>
<View style={[styles.box, styles.red]}/>
<View style={styles.box}/>
</View>
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'space-around',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
box: {
height: 50,
width: 50,
backgroundColor: '#006064',
},
red: {
backgroundColor: 'red',
},
});
Flexbox native/web
• flexDirection defaults
• web: row
• native: column
• flex:
• web: flex-grow, flex-shrink, flex-basis
• flex: 2 2 10%;
• native: flex
• flex: 1;
Platform specific code
//from Home.js
import MyComponent from './MyComponent';
Platform specific code
import {Platform} from 'react-native';
const MyComponent = () =>
<Text>{Platform.OS === 'android' ?
'This is Android' :
'This is iOS'}
</Text>;
Key concepts summary
• Bootstrapping
• Start with Expo, eject if needed
• Primitives
• View => div
• Text => span
• TouchableOpacity => button
• Styling
• Flexbox almost identical to web
• Syntax similar to react-style library styling
• Platform-specific code
• Platform-aware vs platform-agnostic components
Agenda
• Ways to create mobile UI
• React.js in 5 minutes
• React-Native key concepts
• How React-Native works
• Advanced concepts
• React-Native pitfalls
React-Native Virtual DOM
View
Text
Android
react-native
react android.view
android.text
iOS
UIView
UILabel
Reconciliation
class App extends Component {
render() {
return (
<View style={styles.container}>
<Text>
Welcome to React Native!
</Text>
</View>
);
}
}
JS runtime
environment Bridge Native Code
How React-Native works
class App extends Component {
state = {
count: 0,
};
increment = () =>
this.setState({count: this.state.count + 1});
render() {
return (
<View>
<TouchableOpacity
onPress={this.increment}
>
<Text
{this.state.count}
</Text>
</TouchableOpacity>
</View>
);
}
}
Event flow
Source: https://www.slideshare.net/rahatkhanna/introduction-to-react-native-rendering-charts-graphs
Agenda
• Ways to create mobile UI
• React.js in 5 minutes
• React-Native key concepts
• How React-Native works
• Advanced concepts
• React-Native pitfalls
Advanced React-Native
• Navigation
• Animation
Navigation
• react-navigation
• JavaScript-based navigation
• react-native-navigation
• Native implementation navigation
Home screen
class Home extends Component {
static navigationOptions = {
title: 'Home',
};
render() {
const {navigation} = this.props;
return <View>
<TouchableOpacity
onPress={() => navigation.navigate('ThreeBoxes')}
/>
</View>;
}
}
const ModalStack = StackNavigator({
Home: {
screen: Home,
},
ThreeBoxes: {
screen: ThreeBoxes,
},
});
Argues about smooth 60 FPS animation.
But is using gif in presentation?
Animation
class AnimatedBox extends Component {
scale = new Animated.Value(1);
animate = () => {
const timing = (toValue) =>
Animated.timing(this.scale, {
toValue,
duration: 2000,
useNativeDriver: true,
});
const onEnd = () => timing(1).start();
timing(6).start(onEnd);
};
render() {
const transform = [{scaleX: this.scale}, {scaleY: this.scale}];
return (
<View style={styles.container}>
<TouchableOpacity onPress={() => this.animate(this.scale)}>
<Animated.View style={[styles.box, {transform}]}/>
</TouchableOpacity>
</View>
);
}
}
Animation: summary
• Runs on the native thread
• Can achieve 60 FPS even on old Android devices
• Doesn’t use setState (out of react.js component lifecycle)
Agenda
• Ways to create mobile UI
• React.js in 5 minutes
• React-Native key concepts
• How React-Native works
• Advanced concepts
• React-Native pitfalls
React-Native pitfalls
• You still might need a native developer
• React-Native sometimes favors performance over code readability
• Be careful with your state management
• Big state updates might lead to performance degradation
• Android and iOS are very different platforms
Summary
• React-Native: no HTML/CSS, native views defined via JavaScript
• Bridge is key part of js  native communication
• Optimistically: you can write great native mobile apps having only
web experience
• Pessimistically: all abstraction leak and React-Native is no exception
Thanks
Resources
• Getting started with React-Native
• Why not Expo?
• Linking libraries with native code
• Yoga layout engine
• How to use the FlatList Component
• Fetch API
• React Reconciliation
• A Complete Guide to Flexbox
• Repository for the sample application
• Introduction to React-Native performance
• How Airnb is using React-Native
• React-Native workshop
• Animate React Native UI Elements
• React Native: Besides Downsides

More Related Content

What's hot (20)

PDF
An Overview of the React Ecosystem
FITC
 
PDF
Intro To React Native
FITC
 
PDF
[React Native Tutorial] Lecture 6: Component, Props, and Network
Kobkrit Viriyayudhakorn
 
PDF
Ryan Christiani I Heard React Was Good
FITC
 
PDF
Crash Course in AngularJS + Ionic (Deep dive)
ColdFusionConference
 
PDF
React Native custom components
Jeremy Grancher
 
PDF
Modern JavaScript, without giving up on Rails
Jonathan Johnson
 
PDF
Angularjs
Ynon Perek
 
PDF
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Fwdays
 
PDF
Angular js vs. Facebook react
Keyup
 
PDF
AEM Best Practices for Component Development
Gabriel Walt
 
PPTX
Introduction to Sightly and Sling Models
Stefano Celentano
 
PDF
Building Modern Web Applications using React and Redux
Maxime Najim
 
PDF
RESTful services and OAUTH protocol in IoT
Yakov Fain
 
PPTX
React vs Angular: ups & downs (speaker Oleksandr Kovalov, Binary Studio)
Binary Studio
 
PPTX
Rethinking Best Practices
floydophone
 
PDF
Introduction to VueJS & The WordPress REST API
Caldera Labs
 
PDF
What's This React Native Thing I Keep Hearing About?
Evan Stone
 
PDF
Grokking #9: Building a real-time and offline editing service with Couchbase
Oliver N
 
PDF
React Native +Redux + ES6 (Updated)
Chiew Carol
 
An Overview of the React Ecosystem
FITC
 
Intro To React Native
FITC
 
[React Native Tutorial] Lecture 6: Component, Props, and Network
Kobkrit Viriyayudhakorn
 
Ryan Christiani I Heard React Was Good
FITC
 
Crash Course in AngularJS + Ionic (Deep dive)
ColdFusionConference
 
React Native custom components
Jeremy Grancher
 
Modern JavaScript, without giving up on Rails
Jonathan Johnson
 
Angularjs
Ynon Perek
 
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Fwdays
 
Angular js vs. Facebook react
Keyup
 
AEM Best Practices for Component Development
Gabriel Walt
 
Introduction to Sightly and Sling Models
Stefano Celentano
 
Building Modern Web Applications using React and Redux
Maxime Najim
 
RESTful services and OAUTH protocol in IoT
Yakov Fain
 
React vs Angular: ups & downs (speaker Oleksandr Kovalov, Binary Studio)
Binary Studio
 
Rethinking Best Practices
floydophone
 
Introduction to VueJS & The WordPress REST API
Caldera Labs
 
What's This React Native Thing I Keep Hearing About?
Evan Stone
 
Grokking #9: Building a real-time and offline editing service with Couchbase
Oliver N
 
React Native +Redux + ES6 (Updated)
Chiew Carol
 

Similar to React Native: Introduction (20)

PPTX
JS Fest 2018. Илья Иванов. Введение в React-Native
JSFestUA
 
PDF
React && React Native workshop
Stacy Goh
 
PDF
Lessons from a year of building apps with React Native
Ryan Boland
 
PPTX
Ilya Ivanov - Advanced React-Native
OdessaJS Conf
 
PDF
React Native and the future of web technology (Mark Wilcox) - GreeceJS #15
GreeceJS
 
PPTX
Build Mobile Application with React-Native
Đình Khởi Đặng
 
PDF
l1-reactnativeintroduction-160816150540.pdf
Hương Trà Pé Xjnk
 
PDF
ReactJS vs AngularJS - Head to Head comparison
500Tech
 
PDF
React Native Introduction: Making Real iOS and Android Mobile App By JavaScript
Kobkrit Viriyayudhakorn
 
PDF
NativeScript: Cross-Platform Mobile Apps with JavaScript and Angular
Todd Anglin
 
PDF
Mastering JavaScript and DOM: A Gateway to Web Development
Piyumi Niwanthika Herath
 
PDF
React Native - DILo Surabaya
DILo Surabaya
 
PDF
Philip Shurpik "Architecting React Native app"
Fwdays
 
PPTX
React basic by Yoav Amit, Wix
Chen Lerner
 
PPTX
From React to React Native - Things I wish I knew when I started
sparkfabrik
 
PDF
Full Stack React Workshop [CSSC x GDSC]
GDSC UofT Mississauga
 
PDF
Introduction to React for Frontend Developers
Sergio Nakamura
 
PDF
From Backbone to Ember and Back(bone) Again
jonknapp
 
PPTX
20180518 QNAP Seminar - Introduction to React Native
Eric Deng
 
PPTX
NEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfg
zmulani8
 
JS Fest 2018. Илья Иванов. Введение в React-Native
JSFestUA
 
React && React Native workshop
Stacy Goh
 
Lessons from a year of building apps with React Native
Ryan Boland
 
Ilya Ivanov - Advanced React-Native
OdessaJS Conf
 
React Native and the future of web technology (Mark Wilcox) - GreeceJS #15
GreeceJS
 
Build Mobile Application with React-Native
Đình Khởi Đặng
 
l1-reactnativeintroduction-160816150540.pdf
Hương Trà Pé Xjnk
 
ReactJS vs AngularJS - Head to Head comparison
500Tech
 
React Native Introduction: Making Real iOS and Android Mobile App By JavaScript
Kobkrit Viriyayudhakorn
 
NativeScript: Cross-Platform Mobile Apps with JavaScript and Angular
Todd Anglin
 
Mastering JavaScript and DOM: A Gateway to Web Development
Piyumi Niwanthika Herath
 
React Native - DILo Surabaya
DILo Surabaya
 
Philip Shurpik "Architecting React Native app"
Fwdays
 
React basic by Yoav Amit, Wix
Chen Lerner
 
From React to React Native - Things I wish I knew when I started
sparkfabrik
 
Full Stack React Workshop [CSSC x GDSC]
GDSC UofT Mississauga
 
Introduction to React for Frontend Developers
Sergio Nakamura
 
From Backbone to Ember and Back(bone) Again
jonknapp
 
20180518 QNAP Seminar - Introduction to React Native
Eric Deng
 
NEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfg
zmulani8
 
Ad

Recently uploaded (8)

PPTX
The Intersection of Emoji and NFT. What can be the Consequences?
Refit Global
 
PDF
Building Smart, Scalable Solutions with Android App Development
Brancosoft Private Limited
 
PDF
Call For Papers - International Journal on Natural Language Computing (IJNLC)
kevig
 
PDF
💡 Digital Marketing Decoded: Mastering Online Growth Strategies for 2025 🚀
marketingaura24
 
PDF
INTERLINGUAL SYNTACTIC PARSING: AN OPTIMIZED HEAD-DRIVEN PARSING FOR ENGLISH ...
kevig
 
PPTX
Mobile Apps Helping Business Grow in 2025
Infylo Techsolutions
 
PPT
lec2 wireless transmission exlaining.ppt
212231
 
PPT
lect 1 Introduction.ppt11112222333344455
212231
 
The Intersection of Emoji and NFT. What can be the Consequences?
Refit Global
 
Building Smart, Scalable Solutions with Android App Development
Brancosoft Private Limited
 
Call For Papers - International Journal on Natural Language Computing (IJNLC)
kevig
 
💡 Digital Marketing Decoded: Mastering Online Growth Strategies for 2025 🚀
marketingaura24
 
INTERLINGUAL SYNTACTIC PARSING: AN OPTIMIZED HEAD-DRIVEN PARSING FOR ENGLISH ...
kevig
 
Mobile Apps Helping Business Grow in 2025
Infylo Techsolutions
 
lec2 wireless transmission exlaining.ppt
212231
 
lect 1 Introduction.ppt11112222333344455
212231
 
Ad

React Native: Introduction

  • 1. React-Native: Introduction Ilya Ivanov Mobile Team Lead at Payoneer Team Ciklum [email protected] skype: innerself89
  • 2. About me • 1.5 years in react-native • 3 years in web react.js • 3 years in C#/.NET
  • 3. What to expect • React-Native in context • Give you a vision of React-Native • Help you avoid silly mistakes I did when started
  • 4. Agenda • Ways to create mobile UI • React.js in 5 minutes • React-Native key concepts • How React-Native works • Advanced concepts • React-Native pitfalls
  • 5. Ways to create mobile UI 1. Native application (Objective-C/Java) 2. Website running within mobile browser 3. Hybrid application (HTML/JS/CSS in WebView)
  • 8. Ways to create mobile apps summary • React-Native and NativeScript are new ways to create native apps • Each approach is a balance between UX and development speed
  • 9. Agenda • Ways to create mobile UI • React.js in 5 minutes • React-Native key concepts • How React-Native works • Advanced concepts • React-Native pitfalls
  • 10. React.js in 5 minutes • Declarative components • Virtual DOM • One-way data binding
  • 11. Declarative components import React, {Component} from 'react'; class App extends Component { render() { return ( <div> <Title/> <form> <div> <label>Email address</label> <input type="text"/> </div> <br/> <input type="button" value="Submit"/> </form> </div> ); } }
  • 12. Title component const Title = () => <h1>Sign me up!</h1>;
  • 13. Virtual DOM div h1 form div label input br input div Browser DOM div h1 form div label input br input div DiffPatch react-dom react
  • 14. One way data binding Event loop Handle Event Update state Re-render to Virtual DOM Reconcile Browser DOM
  • 15. One way data binding class App extends Component { state = {}; render() { return ( <div> { this.state.submitted && <span>Thanks for submitting your email!</span> } <br/> <input type="button" value="Submit" onClick={() => this.setState({submitted: true})}/> </div> ); } }
  • 16. React.js summary • Declarative components • Return virtual DOM elements • Virtual DOM • Abstracts away browser’s DOM • Change DOM via patches • One-way data binding • Unidirectional data flow • Triggered on explicit state changes (via setState call)
  • 17. Agenda • Ways to create mobile UI • React.js in 5 minutes • React-Native key concepts • How React-Native works • Advanced concepts • React-Native pitfalls
  • 18. React-Native key concepts • Ways to bootstrap • Primitives • Styling • Platform-specific code
  • 19. Bootstrapping your application react-native init MyApplication Pros: • Can use custom native code • Stable in terms of dev experience create-react-native-app MyApplication Pros: • No need to install Android Studio and Xcode • Can publish your apps • You can always eject
  • 20. Initial app class App extends Component { render() { return ( <View style={styles.container}> <Text> Welcome to React Native! </Text> </View> ); } }
  • 21. Primitives • View – fundamental component for building a UI. Supports layout with flexbox. • Similar to div • Text – all text should be wrapped into Text component. • Similar to span • TouchableOpacity – component to handle user press. • Somewhat similar to button
  • 22. class App extends Component { state = { count: 0, }; increment = () => this.setState({count: this.state.count + 1}); render() { return ( <View> <TouchableOpacity onPress={this.increment} > <Text {this.state.count} </Text> </TouchableOpacity> </View> ); } }
  • 23. Styling and flexbox <View style={styles.container}> <View style={styles.box}/> <View style={[styles.box, styles.red]}/> <View style={styles.box}/> </View> const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'space-around', alignItems: 'center', backgroundColor: '#F5FCFF', }, box: { height: 50, width: 50, backgroundColor: '#006064', }, red: { backgroundColor: 'red', }, });
  • 24. Flexbox native/web • flexDirection defaults • web: row • native: column • flex: • web: flex-grow, flex-shrink, flex-basis • flex: 2 2 10%; • native: flex • flex: 1;
  • 25. Platform specific code //from Home.js import MyComponent from './MyComponent';
  • 26. Platform specific code import {Platform} from 'react-native'; const MyComponent = () => <Text>{Platform.OS === 'android' ? 'This is Android' : 'This is iOS'} </Text>;
  • 27. Key concepts summary • Bootstrapping • Start with Expo, eject if needed • Primitives • View => div • Text => span • TouchableOpacity => button • Styling • Flexbox almost identical to web • Syntax similar to react-style library styling • Platform-specific code • Platform-aware vs platform-agnostic components
  • 28. Agenda • Ways to create mobile UI • React.js in 5 minutes • React-Native key concepts • How React-Native works • Advanced concepts • React-Native pitfalls
  • 29. React-Native Virtual DOM View Text Android react-native react android.view android.text iOS UIView UILabel Reconciliation class App extends Component { render() { return ( <View style={styles.container}> <Text> Welcome to React Native! </Text> </View> ); } }
  • 30. JS runtime environment Bridge Native Code How React-Native works
  • 31. class App extends Component { state = { count: 0, }; increment = () => this.setState({count: this.state.count + 1}); render() { return ( <View> <TouchableOpacity onPress={this.increment} > <Text {this.state.count} </Text> </TouchableOpacity> </View> ); } }
  • 33. Agenda • Ways to create mobile UI • React.js in 5 minutes • React-Native key concepts • How React-Native works • Advanced concepts • React-Native pitfalls
  • 35. Navigation • react-navigation • JavaScript-based navigation • react-native-navigation • Native implementation navigation
  • 36. Home screen class Home extends Component { static navigationOptions = { title: 'Home', }; render() { const {navigation} = this.props; return <View> <TouchableOpacity onPress={() => navigation.navigate('ThreeBoxes')} /> </View>; } }
  • 37. const ModalStack = StackNavigator({ Home: { screen: Home, }, ThreeBoxes: { screen: ThreeBoxes, }, });
  • 38. Argues about smooth 60 FPS animation. But is using gif in presentation?
  • 39. Animation class AnimatedBox extends Component { scale = new Animated.Value(1); animate = () => { const timing = (toValue) => Animated.timing(this.scale, { toValue, duration: 2000, useNativeDriver: true, }); const onEnd = () => timing(1).start(); timing(6).start(onEnd); }; render() { const transform = [{scaleX: this.scale}, {scaleY: this.scale}]; return ( <View style={styles.container}> <TouchableOpacity onPress={() => this.animate(this.scale)}> <Animated.View style={[styles.box, {transform}]}/> </TouchableOpacity> </View> ); } }
  • 40. Animation: summary • Runs on the native thread • Can achieve 60 FPS even on old Android devices • Doesn’t use setState (out of react.js component lifecycle)
  • 41. Agenda • Ways to create mobile UI • React.js in 5 minutes • React-Native key concepts • How React-Native works • Advanced concepts • React-Native pitfalls
  • 42. React-Native pitfalls • You still might need a native developer • React-Native sometimes favors performance over code readability • Be careful with your state management • Big state updates might lead to performance degradation • Android and iOS are very different platforms
  • 43. Summary • React-Native: no HTML/CSS, native views defined via JavaScript • Bridge is key part of js  native communication • Optimistically: you can write great native mobile apps having only web experience • Pessimistically: all abstraction leak and React-Native is no exception
  • 45. Resources • Getting started with React-Native • Why not Expo? • Linking libraries with native code • Yoga layout engine • How to use the FlatList Component • Fetch API • React Reconciliation • A Complete Guide to Flexbox • Repository for the sample application • Introduction to React-Native performance • How Airnb is using React-Native • React-Native workshop • Animate React Native UI Elements • React Native: Besides Downsides