SlideShare a Scribd company logo
From Web to Native Mobile App
Eric Deng
2018/05/18 QNAP Seminar
Outline
● What is React Native?
● How does React Native work?
● Writing React Native
○ Expo
○ Components, props, and states
○ Component lifecycle
○ Declarative and imperative
○ Event handling
○ User input
○ Style
○ Layout
○ Data access
● Publishing your Project
What is React Native?
● A framework that let you build native mobile apps using JavaScript
● Relies on React core - A JavaScript library for building user interfaces
○ Component-based
○ High reusability
○ Learn once, write everywhere
● Supports iOS and Android
Why app written by JS is native?
Native App
● Different code and language for different OS
WebView App
● Write once, run everywhere
● Slow and not feeling native
React Native App
● JS components render as native ones
● Difference: JS Runtime, components for specific OS
How does React Native work?
Native
UI (Main) Thread
Native
Modules Thread Bridge JS Thread
Event Queue Event Queue Event Queue
Separate threads for UI, layout and JavaScript
[funID, args]
[funID, args]
Native
UI (Main) Thread
Native
Modules Thread Bridge JS Thread
Event Queue Event Queue Event Queue
E.g., touch, I/O, or networking event
Event
[funID, args]
[funID, args]
Native
UI (Main) Thread
Native
Modules Thread Bridge JS Thread
Event Queue Event Queue Event Queue
Handler
JS thread calls your handler via the bridge
● Asynchronous (event loop are separated)
● Batched (to save overhead)
[funID, args]
[funID, args]
Event
Native
UI (Main) Thread
Native
Modules Thread Bridge JS Thread
Event Queue Event Queue Event Queue
Event Handler
[funID, args]
[funID, args]
Layout
If UI changed in JS, module thread performs
layout first (e.g., measuring size of text)
Update UI
UI thread renders
components
Writing React Native
Expo
Suite of tools to accelerate the React Native development process
● XDE - a GUI to serve, share, and publish your projects
● CLI - a command-line interface to serve, share, and publish your projects
● Client - runs your projects on your phone while developing
● SDK - bundles and exposes cross-platform libraries and APIs
● Snack - React Native online code editor
React Native Packager Device logs
== Webpack
20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native
App.js -
root component
ES6+ features
React Native Components
● import {View, Text, Button} from ‘react-native’
● <View> is like <div> in HTML
● <Text> → <span>
○ Text must be wrapped in <Text>...</Text>
● <Button> → <button>
https://facebook.github.io/react-native/docs/components-and-apis.html
● Custom components
JSX: XML-like syntax extension of JavaScript
Compiled to normal objects by Babel:
React.createElement(Text, {}, 'Hello React Native');
React.Component
render() accepts only a single root element
Two types of data that control a component
● props
● state
props
props
● Changes in props will cause re-renders
● Can be any JS value
● Never change props in a component!
○ So, React can efficiently detect whether a component should be re-
rendered
state
internally-managed configuration for a component
state
● Can only be updated by invoking `this.setState()`
○ Implemented in React.Component
○ `setState()` calls are batched and run asynchronously
○ Changes in state also cause re-renders
state
Error!
ES7 property initializer
this.handleName = this.handleName.bind(this);
state
● If new state depends on previous one (or props)
Less reliable
Lifting State Up
Component Lifecycle
https://github.com/wojtekmaj/react-lifecycle-methods-diagram
avoid!
Component Lifecycle - Mounting
1. constructor() → Ext.Component.initComponent()
○ Initialize state or other class properties
2. render() → Ext.Component.render()
○ Return a node
○ Necessary!
3. componentDidMount() → Ext.Component.afterrender()
○ Do anything that isn’t needed for UI (async actions, network requests, timers, etc.)
Component Lifecycle - Updating
1. shouldComponentUpdate(nextProps, nextState) →
Ext.Component.beforerender()
○ Compare changed values, return true if the component should rerender
○ If returned false, the update cycle terminates
2. render() → Ext.Component.render()
3. componentDidUpdate(prevProps, prevState) → Ext.Component.afterrender()
○ Do anything that isn’t needed for UI.
Component Lifecycle - Unmounting
● componentWillUnmount() → Ext.Component.destroy()
○ Clean up
■ Remove event listeners
■ Clear timeouts/intervals
■ Invalidate network requests
● Fetch API: AbortController.abort()
● socket.close()
1
2
3
4
6
7
5
React is declarative
● Imperative vs Declarative Programming
● Debug-friendly
React is declarative
● Imperative vs Declarative Programming
● Debug-friendly
When writing React,
not to think of how you want to accomplish a result,
but instead what the component should look like in its new state.
Event Handling
● <Button title=”” onPress={handle function} />
● <TouchableHighlight>
● <TouchableOpacity>
● <TouchableWithoutFeedback>
● <TouachableNativeFeedback> (Android only)
User input
Controlled component
Uncontrolled component
Style
● Native design
● ex: <Button> import from react-native
iOS Android
Style
values have no unit
pass an array of styles
css properties are written using camel casing
assign style prop to components
Style
● StyleSheet.create()
○ Additional optimization: Allows multiple native components to refer to same style object (by ID)
Layout
● Container component is default to Flexbox layout
○ flexDirection: ‘column’
○ justifyContent: ‘flex-start’ (alignment along the main axis)
○ alignItems: ‘stretch’ (alignment along the cross axis)
● Contained component:
○ width/height: number
○ alignSelf: auto|stretch|center|flex-start|flex-end|baseline|initial
○ flex: number
main axis
cross axis
flex: 1
flex: 2
flex: 3
Data access
Fetch API
HTML5 Web API
Apps on Apple's App Store shall use HTTPS
Publishing your Project
1. Set metadata in app.json
○ https://docs.expo.io/versions/latest/workflow/configuration
2. Build the app using exp (Expo CLI)
○ Install with `npm install --global exp`
○ Build .apk with `exp build:ios` for Android
○ Build .ipa with `exp build:android` for iOS
○ Run `exp build:status` and paste the url in a browser to download
3. Upload to the appropriate store
○ https://docs.expo.io/versions/latest/distribution/building-standalone-apps
○ https://docs.expo.io/versions/latest/distribution/app-stores
Summary
1. Component-based
2. JS components render as native ones
3. Separate threads for UI, layout and JavaScript
4. Props are fixed throughout the lifetime of a component
5. setState() calls are batched and run asynchronously
6. Component lifecycle: Mounting, Updating, Unmounting
7. Declarative programming
8. Controlled component
More
● ScrollView
● Lists
○ FlatList
○ SectionList
● Persistent Storage - AsyncStorage
● React-navigation - routing and navigation for your React Native apps
● Redux - predictable state container for JavaScript apps
● ...
Reference
React Native
React
Expo
Mobile App Development with React Native
Q&A
Thank you!
20180518 QNAP Seminar - Introduction to React Native
Differences between React Native and React (Web)
● Base components
● Event Handling
● Style
● No browser APIs
○ Some have been polyfilled (fetch, timers, console, etc.)
● Navigation
Fast Re-rendering
● React keeps a virtual DOM in memory
○ Diffs the virtual DOM against the real DOM
○ Updates only changed elements in real ROM
● Reconciliation
Ad

More Related Content

What's hot (20)

Introduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace ITIntroduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace IT
namespaceit
 
React workshop presentation
React workshop presentationReact workshop presentation
React workshop presentation
Bojan Golubović
 
Introduction to React JS for beginners
Introduction to React JS for beginners Introduction to React JS for beginners
Introduction to React JS for beginners
Varun Raj
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
洪 鹏发
 
An introduction to React.js
An introduction to React.jsAn introduction to React.js
An introduction to React.js
Emanuele DelBono
 
Introduction to ReactJS
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJS
Hoang Long
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Preview
valuebound
 
Intro to React
Intro to ReactIntro to React
Intro to React
Eric Westfall
 
Basics of React Hooks.pptx.pdf
Basics of React Hooks.pptx.pdfBasics of React Hooks.pptx.pdf
Basics of React Hooks.pptx.pdf
Knoldus Inc.
 
Introduction to React
Introduction to ReactIntroduction to React
Introduction to React
Rob Quick
 
React workshop
React workshopReact workshop
React workshop
Imran Sayed
 
Its time to React.js
Its time to React.jsIts time to React.js
Its time to React.js
Ritesh Mehrotra
 
React Native
React NativeReact Native
React Native
Fatih Şimşek
 
React Js Simplified
React Js SimplifiedReact Js Simplified
React Js Simplified
Sunil Yadav
 
ReactJs
ReactJsReactJs
ReactJs
Sahana Banerjee
 
Learn react-js
Learn react-jsLearn react-js
Learn react-js
C...L, NESPRESSO, WAFAASSURANCE, SOFRECOM ORANGE
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux Introduction
Nikolaus Graf
 
React hooks
React hooksReact hooks
React hooks
Sadhna Rana
 
React js
React jsReact js
React js
Jai Santhosh
 
reactJS
reactJSreactJS
reactJS
Syam Santhosh
 

Similar to 20180518 QNAP Seminar - Introduction to React Native (20)

Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]
GDSC UofT Mississauga
 
Lecture 1 Introduction to React Native.pptx
Lecture 1 Introduction to React Native.pptxLecture 1 Introduction to React Native.pptx
Lecture 1 Introduction to React Native.pptx
GevitaChinnaiah
 
Philip Shurpik "Architecting React Native app"
Philip Shurpik "Architecting React Native app"Philip Shurpik "Architecting React Native app"
Philip Shurpik "Architecting React Native app"
Fwdays
 
React Native for multi-platform mobile applications
React Native for multi-platform mobile applicationsReact Native for multi-platform mobile applications
React Native for multi-platform mobile applications
Matteo Manchi
 
From React to React Native - Things I wish I knew when I started
From React to React Native - Things I wish I knew when I startedFrom React to React Native - Things I wish I knew when I started
From React to React Native - Things I wish I knew when I started
sparkfabrik
 
Angular kickstart slideshare
Angular kickstart   slideshareAngular kickstart   slideshare
Angular kickstart slideshare
SaleemMalik52
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React Native
Damian Zbrożek
 
React Native custom components
React Native custom componentsReact Native custom components
React Native custom components
Jeremy Grancher
 
Intro to Flutter SDK
Intro to Flutter SDKIntro to Flutter SDK
Intro to Flutter SDK
digitaljoni
 
React native
React nativeReact native
React native
Vikrant Negi
 
React_Complete.pptx
React_Complete.pptxReact_Complete.pptx
React_Complete.pptx
kamalakantas
 
Intro to Flutter
Intro to FlutterIntro to Flutter
Intro to Flutter
Eason Pai
 
Introduction to react native @ TIC NUST
Introduction to react native @ TIC NUSTIntroduction to react native @ TIC NUST
Introduction to react native @ TIC NUST
Waqqas Jabbar
 
GDSC NITS Presents Kickstart into ReactJS
GDSC NITS Presents Kickstart into ReactJSGDSC NITS Presents Kickstart into ReactJS
GDSC NITS Presents Kickstart into ReactJS
Pratik Majumdar
 
React for non techies
React for non techiesReact for non techies
React for non techies
React London Community
 
React for Non Techies
React for Non TechiesReact for Non Techies
React for Non Techies
Jack Hoy
 
Web App Prototypes with Google App Engine
Web App Prototypes with Google App EngineWeb App Prototypes with Google App Engine
Web App Prototypes with Google App Engine
Vlad Filippov
 
React for non techies
React for non techiesReact for non techies
React for non techies
Amy Crimmens
 
Utilizing HTML5 APIs
Utilizing HTML5 APIsUtilizing HTML5 APIs
Utilizing HTML5 APIs
Ido Green
 
Angular meetup 2 2019-08-29
Angular meetup 2   2019-08-29Angular meetup 2   2019-08-29
Angular meetup 2 2019-08-29
Nitin Bhojwani
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]
GDSC UofT Mississauga
 
Lecture 1 Introduction to React Native.pptx
Lecture 1 Introduction to React Native.pptxLecture 1 Introduction to React Native.pptx
Lecture 1 Introduction to React Native.pptx
GevitaChinnaiah
 
Philip Shurpik "Architecting React Native app"
Philip Shurpik "Architecting React Native app"Philip Shurpik "Architecting React Native app"
Philip Shurpik "Architecting React Native app"
Fwdays
 
React Native for multi-platform mobile applications
React Native for multi-platform mobile applicationsReact Native for multi-platform mobile applications
React Native for multi-platform mobile applications
Matteo Manchi
 
From React to React Native - Things I wish I knew when I started
From React to React Native - Things I wish I knew when I startedFrom React to React Native - Things I wish I knew when I started
From React to React Native - Things I wish I knew when I started
sparkfabrik
 
Angular kickstart slideshare
Angular kickstart   slideshareAngular kickstart   slideshare
Angular kickstart slideshare
SaleemMalik52
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React Native
Damian Zbrożek
 
React Native custom components
React Native custom componentsReact Native custom components
React Native custom components
Jeremy Grancher
 
Intro to Flutter SDK
Intro to Flutter SDKIntro to Flutter SDK
Intro to Flutter SDK
digitaljoni
 
React_Complete.pptx
React_Complete.pptxReact_Complete.pptx
React_Complete.pptx
kamalakantas
 
Intro to Flutter
Intro to FlutterIntro to Flutter
Intro to Flutter
Eason Pai
 
Introduction to react native @ TIC NUST
Introduction to react native @ TIC NUSTIntroduction to react native @ TIC NUST
Introduction to react native @ TIC NUST
Waqqas Jabbar
 
GDSC NITS Presents Kickstart into ReactJS
GDSC NITS Presents Kickstart into ReactJSGDSC NITS Presents Kickstart into ReactJS
GDSC NITS Presents Kickstart into ReactJS
Pratik Majumdar
 
React for Non Techies
React for Non TechiesReact for Non Techies
React for Non Techies
Jack Hoy
 
Web App Prototypes with Google App Engine
Web App Prototypes with Google App EngineWeb App Prototypes with Google App Engine
Web App Prototypes with Google App Engine
Vlad Filippov
 
React for non techies
React for non techiesReact for non techies
React for non techies
Amy Crimmens
 
Utilizing HTML5 APIs
Utilizing HTML5 APIsUtilizing HTML5 APIs
Utilizing HTML5 APIs
Ido Green
 
Angular meetup 2 2019-08-29
Angular meetup 2   2019-08-29Angular meetup 2   2019-08-29
Angular meetup 2 2019-08-29
Nitin Bhojwani
 
Ad

Recently uploaded (20)

Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 
FL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full VersionFL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full Version
tahirabibi60507
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
EASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License CodeEASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License Code
aneelaramzan63
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 
FL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full VersionFL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full Version
tahirabibi60507
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
EASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License CodeEASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License Code
aneelaramzan63
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
Ad

20180518 QNAP Seminar - Introduction to React Native

  • 1. From Web to Native Mobile App Eric Deng 2018/05/18 QNAP Seminar
  • 2. Outline ● What is React Native? ● How does React Native work? ● Writing React Native ○ Expo ○ Components, props, and states ○ Component lifecycle ○ Declarative and imperative ○ Event handling ○ User input ○ Style ○ Layout ○ Data access ● Publishing your Project
  • 3. What is React Native? ● A framework that let you build native mobile apps using JavaScript ● Relies on React core - A JavaScript library for building user interfaces ○ Component-based ○ High reusability ○ Learn once, write everywhere ● Supports iOS and Android
  • 4. Why app written by JS is native?
  • 5. Native App ● Different code and language for different OS
  • 6. WebView App ● Write once, run everywhere ● Slow and not feeling native
  • 7. React Native App ● JS components render as native ones ● Difference: JS Runtime, components for specific OS
  • 8. How does React Native work?
  • 9. Native UI (Main) Thread Native Modules Thread Bridge JS Thread Event Queue Event Queue Event Queue Separate threads for UI, layout and JavaScript [funID, args] [funID, args]
  • 10. Native UI (Main) Thread Native Modules Thread Bridge JS Thread Event Queue Event Queue Event Queue E.g., touch, I/O, or networking event Event [funID, args] [funID, args]
  • 11. Native UI (Main) Thread Native Modules Thread Bridge JS Thread Event Queue Event Queue Event Queue Handler JS thread calls your handler via the bridge ● Asynchronous (event loop are separated) ● Batched (to save overhead) [funID, args] [funID, args] Event
  • 12. Native UI (Main) Thread Native Modules Thread Bridge JS Thread Event Queue Event Queue Event Queue Event Handler [funID, args] [funID, args] Layout If UI changed in JS, module thread performs layout first (e.g., measuring size of text) Update UI UI thread renders components
  • 14. Expo Suite of tools to accelerate the React Native development process ● XDE - a GUI to serve, share, and publish your projects ● CLI - a command-line interface to serve, share, and publish your projects ● Client - runs your projects on your phone while developing ● SDK - bundles and exposes cross-platform libraries and APIs ● Snack - React Native online code editor
  • 15. React Native Packager Device logs == Webpack
  • 20. React Native Components ● import {View, Text, Button} from ‘react-native’ ● <View> is like <div> in HTML ● <Text> → <span> ○ Text must be wrapped in <Text>...</Text> ● <Button> → <button> https://facebook.github.io/react-native/docs/components-and-apis.html ● Custom components JSX: XML-like syntax extension of JavaScript Compiled to normal objects by Babel: React.createElement(Text, {}, 'Hello React Native');
  • 22. render() accepts only a single root element
  • 23. Two types of data that control a component ● props ● state
  • 24. props
  • 25. props ● Changes in props will cause re-renders ● Can be any JS value ● Never change props in a component! ○ So, React can efficiently detect whether a component should be re- rendered
  • 27. state ● Can only be updated by invoking `this.setState()` ○ Implemented in React.Component ○ `setState()` calls are batched and run asynchronously ○ Changes in state also cause re-renders
  • 29. state ● If new state depends on previous one (or props) Less reliable
  • 32. Component Lifecycle - Mounting 1. constructor() → Ext.Component.initComponent() ○ Initialize state or other class properties 2. render() → Ext.Component.render() ○ Return a node ○ Necessary! 3. componentDidMount() → Ext.Component.afterrender() ○ Do anything that isn’t needed for UI (async actions, network requests, timers, etc.)
  • 33. Component Lifecycle - Updating 1. shouldComponentUpdate(nextProps, nextState) → Ext.Component.beforerender() ○ Compare changed values, return true if the component should rerender ○ If returned false, the update cycle terminates 2. render() → Ext.Component.render() 3. componentDidUpdate(prevProps, prevState) → Ext.Component.afterrender() ○ Do anything that isn’t needed for UI.
  • 34. Component Lifecycle - Unmounting ● componentWillUnmount() → Ext.Component.destroy() ○ Clean up ■ Remove event listeners ■ Clear timeouts/intervals ■ Invalidate network requests ● Fetch API: AbortController.abort() ● socket.close()
  • 36. React is declarative ● Imperative vs Declarative Programming ● Debug-friendly
  • 37. React is declarative ● Imperative vs Declarative Programming ● Debug-friendly When writing React, not to think of how you want to accomplish a result, but instead what the component should look like in its new state.
  • 38. Event Handling ● <Button title=”” onPress={handle function} /> ● <TouchableHighlight> ● <TouchableOpacity> ● <TouchableWithoutFeedback> ● <TouachableNativeFeedback> (Android only)
  • 40. Style ● Native design ● ex: <Button> import from react-native iOS Android
  • 41. Style values have no unit pass an array of styles css properties are written using camel casing assign style prop to components
  • 42. Style ● StyleSheet.create() ○ Additional optimization: Allows multiple native components to refer to same style object (by ID)
  • 43. Layout ● Container component is default to Flexbox layout ○ flexDirection: ‘column’ ○ justifyContent: ‘flex-start’ (alignment along the main axis) ○ alignItems: ‘stretch’ (alignment along the cross axis) ● Contained component: ○ width/height: number ○ alignSelf: auto|stretch|center|flex-start|flex-end|baseline|initial ○ flex: number main axis cross axis flex: 1 flex: 2 flex: 3
  • 44. Data access Fetch API HTML5 Web API Apps on Apple's App Store shall use HTTPS
  • 45. Publishing your Project 1. Set metadata in app.json ○ https://docs.expo.io/versions/latest/workflow/configuration 2. Build the app using exp (Expo CLI) ○ Install with `npm install --global exp` ○ Build .apk with `exp build:ios` for Android ○ Build .ipa with `exp build:android` for iOS ○ Run `exp build:status` and paste the url in a browser to download 3. Upload to the appropriate store ○ https://docs.expo.io/versions/latest/distribution/building-standalone-apps ○ https://docs.expo.io/versions/latest/distribution/app-stores
  • 46. Summary 1. Component-based 2. JS components render as native ones 3. Separate threads for UI, layout and JavaScript 4. Props are fixed throughout the lifetime of a component 5. setState() calls are batched and run asynchronously 6. Component lifecycle: Mounting, Updating, Unmounting 7. Declarative programming 8. Controlled component
  • 47. More ● ScrollView ● Lists ○ FlatList ○ SectionList ● Persistent Storage - AsyncStorage ● React-navigation - routing and navigation for your React Native apps ● Redux - predictable state container for JavaScript apps ● ...
  • 48. Reference React Native React Expo Mobile App Development with React Native
  • 49. Q&A
  • 52. Differences between React Native and React (Web) ● Base components ● Event Handling ● Style ● No browser APIs ○ Some have been polyfilled (fetch, timers, console, etc.) ● Navigation
  • 53. Fast Re-rendering ● React keeps a virtual DOM in memory ○ Diffs the virtual DOM against the real DOM ○ Updates only changed elements in real ROM ● Reconciliation

Editor's Notes

  • #30: state may be updated asynchronously and we should not rely on its values for calculating the next state
  • #36: Component Lifecycle simple example
  • #37: https://codeburst.io/declarative-vs-imperative-programming-a8a7c93d9ad2
  • #38: https://codeburst.io/declarative-vs-imperative-programming-a8a7c93d9ad2
  • #40: https://goshakkk.name/controlled-vs-uncontrolled-inputs-react/