SlideShare une entreprise Scribd logo
1  sur  68
Télécharger pour lire hors ligne
THE GIST OF REACT-NATIVE
What it is,
Why you’d use it
August 11, 2016
Darren Cruse darren.cruse@gmail.com
This Talk is in Beta
Expect Bugs
and
Possible Crashes
send feedback to: darren.cruse@gmail.com
(my journey thru UI development developments)
About your speaker…
• 51 years old (old old old so very old grim
reaper get away from me!)
• used various languages:
asm, C, C++, Perl, Java, Groovy, Javascript
• did desktop GUI programming before the
web (Mac, Unix X Windows, Java Swing)
• spent the last 13 years doing web
applications
• haven’t done any mobile apps in the app
stores
• I’m still learning react-native  
My last 13 years doing web applications
(too much code, esp. for so-so user experiences)
And then this guy famously said about html5…
This seemed part of a “meme”…
The prevalent (though not universal) idea
that:
“To provide the best user experience you have
to use native platform SDKs and languages,
not cross platform tools and e.g. not the hybrid
phonegap/cordova approach”
*Apple’s early fights against flash on iOS, the restrictions against interpreted
code, etc. seemed part of this “meme” as well.
Was the Mobile Train Passing Me By?
So I bought all the toys
And started doing my homework…
BUT OMG…
Web apps during the day,
and all this too?
So I started a personal quest evaluating cross
platform mobile tools on my weekends…
Titanium
RunRev
LiveCode
NativeScript
Tabris.js
JavaFX
Adobe Flex
Xamarin
Lambda
Native
Qt Quick QML
Famo.usjQuery Mobile
Sencha
But Mobile remained a side interest…
(Nylas email client written in html/css with Electron)
Then recently came some great html UIs
(Atom editor written in html/css with Electron)
Then recently came some great html UIs
(Deco react-native IDE written in html/css with Electron - irony?)
Then recently came some great html UIs
So maybe html5 was underestimated?
*Though I notice many of these great hybrid html based
apps have an emphasis on *text* - maybe not a coincidence?
And then I see stuff like this…
https://yahoodevelopers.tumblr.com/post/127636051988/seven-years-into-the-mobile-revolution-content-is
I’M SO CONFUSED!!
(do I want to focus on web apps or on native apps?!)
BUT THEN CAME:
REACT
AND
REACT-NATIVE
AND IT’S NO LONGER
“WEB APPS
OR
NATIVE APPS”
IT’S
“WEB APPS
AND
NATIVE APPS!!”
SO…
REACT
=
USE YOUR
WEB DEVELOPER SKILLS
FOR WEB APPS
(AS YOU’D EXPECT)
AND:
REACT-NATIVE
=
USE YOUR WEB DEVELOPER SKILLS
FOR
MOBILE APPS
(BUT MINUS THE HTML)
END OF STORY.
MY QUEST HAS ENDED!
(MAYBE?)
BUT WAIT YOU SAY?
DIDN’T YOU ALSO
JUST MAKE A PITCH FOR:
PHONEGAP/CORDOVA,
IONIC,
ELECTRON,
ETC?
SINCE THEY TOO LET YOU
DEVELOP MOBILE APPS
USING YOUR
“WEB DEVELOPER SKILLS”?
MY DEFINITIVE ANSWER:
MY DEFINITIVE ANSWER:
YES AND NO
MY DEFINITIVE ANSWER:
YES AND NO
END OF STORY.
MY DEFINITIVE ANSWER:
YES AND NO
END OF STORY.
(KIDDING)
The React-Native Folks would say this:
Those other tools are fighting that “meme”.
The meme that you *must* write mobile apps
using native SDKs for the best possible user
experience.
We (the folks behind react-native) are not.
*We* are truly native mobile apps without
compromise!!
More details:
• React-native is truly claiming they are super close to the goal that you
can write cross-platform apps that are indistinguishable to the user
from those you wrote directly using the native sdks.
• They say they rejected the idea (like from java) of “write once run
anywhere” knowing that would lead to compromises for the user
experience because the browser, iOS, and Android *are different*.
They *do* have different “look and feels”, “style guides”, etc.
• Their motto is “learn once write anywhere” meaning you learn the
react programming model and apply that uniquely on each platform.
• In practice this means having a lot of shared javascript code between
your browser (react), iOS and Android (react-native) applications, but
with a (hopefully) small amount of code (and UI markup) using the
unique platform SDKs if and when needed.
So what is this “React Programming Model”?
(note: react as opposed to react-native)
• HTML *in* your javascript Code (not a separate
template)
• React Components (i.e. “Custom Tags”)
• Explicit definition and handling of “program state”
• UI as a *function* of that state
• No direct manipulation of the DOM
• Because the framework *automatically* updates the
UI for you
HTML *in* your javascript Code = JSX
(not a separate template)
TodoApp.js
/** @jsx React.DOM */
var React = require('react');
var TodoList = require('./TodoList');
class TodoApp {
getInitialState () {
return {
allTodos: TodoStore.getAll()
};
}
render () {
return (
<div>
<Header />
<TodoList todos={this.state.allTodos} />
<Footer todos={this.state.allTodos} />
</div>
)
}
}
module.exports = React.createClass(TodoApp.prototype);
example code from: https://github.com/edvinerikson/ES6-TodoMVC-React
curly braces escape
out to javascript
when inside JSX
tags.
React Components
• i.e. “Custom Tags”. don’t just use html - invent your own tags! Similar
(but incompatible) to Angular “Directives” and W3C Web Components
https://facebook.github.io/react/docs/webcomponents.html
TodoItem.js
/** @jsx React.DOM */
var React = require('react');
var TodoItem = require('./TodoItem');
class TodoList {
render () {
return (
<section id="main">
<input id="toggle-all" type="checkbox" />
<label htmlFor="toggle-all">Mark all as completed</label>
<ul id="todo-list">
{this.props.todos.toJSON().map((todo) => {
return <TodoItem key={todo.id} todo={todo} />
})}
</ul>
</section>
)
}
}
module.exports = React.createClass(TodoList.prototype);
TodoList.js
/** @jsx React.DOM */
var React = require('react');
class TodoItem {
// stuff (omitted for brevity)
}
module.exports = React.createClass(TodoItem.prototype);
note the
components are
just CommonJS
modules
Explicit definition and handling of
“program state”
/** @jsx React.DOM */
var React = require('react');
var TodoTextInput = require('./TodoTextInput');
class TodoItem {
getInitialState () { return {isEditing: false} }
render () {
let todo = this.props.todo;
let input;
if(this.state.isEditing) {
input = <TodoTextInput className="edit" onSave={this.setState({isEditing: false})}
value={todo.title} />
}
return (
<li
className={cx({'completed': todo.completed,'editing': this.state.isEditing})}
key={todo.id}>
<div className="view">
<input className="toggle" type="checkbox" checked={todo.completed}
onChange={this._onToggleComplete} />
<label onDoubleClick={this._onDoubleClick}>
{todo.title}
</label>
<button className="destroy" onClick={this._onDestroyClick} />
</div>
{input}
</li>
)
}
}
UI as a function of that state
UI = f(state)
/** @jsx React.DOM */
var React = require('react');
var TodoTextInput = require('./TodoTextInput');
class TodoItem {
getInitialState () { return {isEditing: false} }
render () {
let todo = this.props.todo;
let input;
if(this.state.isEditing) {
input = <TodoTextInput className="edit" onSave={this.setState({isEditing: false})}
value={todo.title} />
}
return (
<li
className={cx({'completed': todo.completed,'editing': this.state.isEditing})}
key={todo.id}>
<div className="view">
<input className="toggle" type="checkbox" checked={todo.completed}
onChange={this._onToggleComplete} />
<label onDoubleClick={this._onDoubleClick}>
{todo.title}
</label>
<button className="destroy" onClick={this._onDestroyClick} />
</div>
{input}
</li>
)
}
}
"No direct manipulation of the DOM” and
"the framework automagically updates the UI for you"
• You’re using the react “Virtual DOM” (what JSX is transpiled into). Note
this can run under node just fine (e.g. for server side rendering).
• React internally uses “DOM Diffing” to identify and update only the parts
of the DOM that really need to change.
diagram from: https://www.infoq.com/articles/react-native-introduction
HOW’S THIS DIFFERENT
IN REACT-NATIVE?
THE KEY DIFFERENCE:
THERE IS NO BROWSER
AND SO THERE IS NO BROWSER DOM
For the programmer:
it’s almost the same
• It’s just that instead of html tags we now have tags corresponding to native
widgets
• So in react-native the “DOM Diffing” plumbing is replaced with code that
renders UI using native widget SDKs.
diagram from: https://www.infoq.com/articles/react-native-introduction
The “Bridge”
• The Bridge allows asynchronous calling from JS to Native and from Native to
JS. Likewise native events are sent to the JS event handlers.
• JSON messages are passed
• These run in different threads - usually on the one mobile device
• But you can also run the JS in chrome over a websocket in order to
live edit and even use the chrome debugger against your running
mobile app - this is a great developer experience(!!)
diagram from: https://www.infoq.com/articles/react-native-introduction
Javascript
VM
Native
Code
Regarding The “Developer Experience”:
Here’s the Developer Menu
(this appears
when you
“shake gesture”
your app)
An example of Debugging JS in Chrome
You can use “.ios.js” and “.android.js” extensions
(though you don’t often need to)
example code from: https://github.com/thebakeryio/todomvc-react-native
render() {
return (
<View style={ styles.container }>
{ Platform.OS === 'ios' ? <AddTodoItem /> : null }
<MainNavigation />
</View>
);
}
Or you can also look at “Platform.OS”
within your “generic” code files:
Some example code
(part of the ios file from the previous slide)
index.ios.jsclass MainNavigation extends Component {
render() {
const children = mainNavigation.routes.map( (tab, i) => {
return (
<TabBarIOS.Item key={tab.key}
icon={tab.icon}
selectedIcon={tab.selectedIcon}
title={tab.title} onPress={
() => dispatch(jumpTo(i, mainNavigation.key))
}
selected={this.props.mainNavigation.index === i}>
{ this._renderTabContent(tab) }
</TabBarIOS.Item>
);
});
return (
<TabBarIOS>
{children}
</TabBarIOS>
);
}
_renderTabContent(tab) {
return (
<View style={ styles.container }>
<TodoList filter={tab.key} />
</View>
);
}
}
Some example code
(part of the android file from the previous slide)
index.android.jsclass MainNavigation extends Component {
render() {
return (
<DrawerLayoutAndroid
ref={(drawer) => { this.drawer = drawer; }}
drawerWidth={300}
drawerPosition={DrawerLayoutAndroid.positions.Left}
renderNavigationView={this._renderNavigation.bind(this)}>
{this._renderContent()}
</DrawerLayoutAndroid>
);
}
_renderTabContent(tab) {
return (
<View style={ styles.container }>
<TodoList filter={tab.key} />
</View>
);
}
_renderContent() {
return (
<View style={ styles.container }>
<ToolbarAndroid
style={androidToolbarStyle}
navIcon={navigationIcon}
onIconClicked={() => this.drawer.openDrawer()}
title={selectedTab.title}
/>
<AddTodoItem />
{this._renderTabContent(selectedTab)}
</View>
);
}
}
note some of the
top level nav
components
differ between
iOS and android
but our “TodoList”
component
does not.
CSS is supported, with Flexbox for layout
(but the CSS is done in javascript)
index.ios.js
import { StyleSheet } from 'react-native';
export default StyleSheet.create({
container: {
flex: 1
},
header: {
fontSize: 50,
textAlign: 'center',
color: 'rgba(175, 47, 47, 0.15)',
marginTop: 50,
marginBottom: 100
},
navigationMenuItem: {
borderBottomWidth: StyleSheet.hairlineWidth,
borderBottomColor: '#ededed',
flexDirection: 'row',
paddingTop: 15,
paddingBottom: 15,
paddingLeft: 15
},
label: {
fontSize: 24,
marginLeft: 10
}
});
in this case the styles have been
put in their own module so both
the iOS and Android versions
could use them. Since it’s just
javascript sometimes it’s just in
the component’s module file with
the rest.
import styles from ‘./styles';
(other stuff then…)
_renderTabContent(tab) {
return (
<View style={ styles.container }>
<TodoList filter={tab.key} />
</View>
);
}
styles.js
STATE OF REACT-NATIVE
(AS OF AUG 2016)
React-Native is still young
(yet it’s being used anyway)
• Current (as of August 2016) version is 0.32
• Only iOS and Android are officially supported by Facebook
• Outside projects are in development for using React-Native to
build:
•Windows “Universal Apps”
•Mac OS X desktop apps
•Ubuntu Desktop Apps
•AppleTV Apps
•Samsung Tizen SmartTV/SmartWatch Apps
And for some of you…
A React Native renderer for Angular 2
http://angularjs.blogspot.com/2016/04/angular-2-react-native.html
List of production apps:
https://facebook.github.io/react-native/showcase.html
React Native Job Market (Aug 2016)
# of jobs searching indeed.com for “react native”
California: 78
New York: 26
Pennsylvania 23
Texas: 22
Washington State:
14
Illinois: 11
Missouri: 1
note: many of the above are not *directly* react-native
projects, but show because they list it as a “nice to have”.
GETTING STARTED
Some Tips
• instructions at:
https://facebook.github.io/react-native/docs/getting-started.html
• for developing for android:
you can use windows, linux, or Mac as your development
machine
• for developing for iOS:
you have to have a Mac for your development machine.
in fact I had trouble with react-native on an older Mac running
Mavericks - I actually upgraded to El Capitan just for react-
native.
(I don’t now if this has been reported by others but just a
warning FYI)
RESOURCES
official main site:
https://facebook.github.io/react-native/
easier to remember:
http://www.reactnative.com
docs link
on the left
goes to
facebook
site
Books
React-Native Themes
and Starter Kits…
https://strapmobile.com
googling shows up
quite a few both free
and commercial…
The one to the right is
called “Native Starter Kit”
(click image for animation)
“Native Starter Kit
Flat Theme”
https://strapmobile.com
just another example…
(click image for animation)
Theme Example: Material Design
https://github.com/binggg/MaterialReactNative
again - just an example (there’s even multiple Material Design projects)
Caveats
(It’s not all wine and roses!)
Note react-native is building and deploying full android and iOS apps using all the
same build and deployment tools that a natively written app would use.

As I put slides away and went back to trying some code examples, I was hitting
some errors running various examples written for older and/or newer versions of
react-native than the one I have installed on my machine.

Maybe I need to learn how to properly upgrade react-native and/or projects to work
with newer versions of react-native, or maybe this is an area for improvement in
react-native as it matures.

Debugging the errors (e.g. java compilation errors) benefitted from having a little java/
android or iOS development experience. 

It makes me think at a serious company targeting browser, android, and iOS they will
benefit greatly from an android developer and an iOS developer. Even if the rest of
the team are javascript developers. 

It could still be *one team* so it’s much better than the alternative of having *three*
teams. But it’s not all wine and roses (this is different than typical browser
development!).
RESOURCES
Most but not all repeated from the previous slides but:
https://facebook.github.io/react-native/
http://www.reactnative.com
https://facebook.github.io/react-native/showcase.html
https://react.parts/native
https://strapmobile.com
https://github.com/binggg/MaterialReactNative
http://shop.oreilly.com/product/0636920041511.do
https://www.packtpub.com/application-development/getting-started-react-native
THANKS
(AND AS BRENDON EICH SAYS…)
http://brendaneich.github.io/ModernWeb.tw-2015/#74

Contenu connexe

Tendances

From zero to hero with React Native!
From zero to hero with React Native!From zero to hero with React Native!
From zero to hero with React Native!Commit University
 
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
 
Creating books app with react native
Creating books app with react nativeCreating books app with react native
Creating books app with react nativeAli Sa'o
 
React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)Chiew Carol
 
Introduction to react native
Introduction to react nativeIntroduction to react native
Introduction to react nativeDani Akash
 
Optimizing React Native views for pre-animation
Optimizing React Native views for pre-animationOptimizing React Native views for pre-animation
Optimizing React Native views for pre-animationModusJesus
 
Pieter De Baets - An introduction to React Native
Pieter De Baets - An introduction to React NativePieter De Baets - An introduction to React Native
Pieter De Baets - An introduction to React Nativetlv-ios-dev
 
React-Native for multi-platform mobile applications @ Codemotion Rome 2017
React-Native for multi-platform mobile applications @ Codemotion Rome 2017React-Native for multi-platform mobile applications @ Codemotion Rome 2017
React-Native for multi-platform mobile applications @ Codemotion Rome 2017Matteo Manchi
 
A Closer Look At React Native
A Closer Look At React NativeA Closer Look At React Native
A Closer Look At React NativeIan Wang
 
Intro to react native
Intro to react nativeIntro to react native
Intro to react nativeModusJesus
 
React native: building native iOS apps with javascript
React native: building native iOS apps with javascriptReact native: building native iOS apps with javascript
React native: building native iOS apps with javascriptPolidea
 
Intro To React Native
Intro To React NativeIntro To React Native
Intro To React NativeFITC
 
Build a lego app with CocoaPods
Build a lego app with CocoaPodsBuild a lego app with CocoaPods
Build a lego app with CocoaPodsCocoaHeads France
 
React JS Belgium Touch Base - React, Flux, React Native
React JS Belgium Touch Base - React, Flux, React NativeReact JS Belgium Touch Base - React, Flux, React Native
React JS Belgium Touch Base - React, Flux, React NativePhilos.io
 
Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6William Marques
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React NativePolidea
 
React Native - Workshop
React Native - WorkshopReact Native - Workshop
React Native - WorkshopFellipe Chagas
 

Tendances (20)

From zero to hero with React Native!
From zero to hero with React Native!From zero to hero with React Native!
From zero to hero with React Native!
 
Philip Shurpik "Architecting React Native app"
Philip Shurpik "Architecting React Native app"Philip Shurpik "Architecting React Native app"
Philip Shurpik "Architecting React Native app"
 
Creating books app with react native
Creating books app with react nativeCreating books app with react native
Creating books app with react native
 
React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)
 
Introduction to react native
Introduction to react nativeIntroduction to react native
Introduction to react native
 
Optimizing React Native views for pre-animation
Optimizing React Native views for pre-animationOptimizing React Native views for pre-animation
Optimizing React Native views for pre-animation
 
Pieter De Baets - An introduction to React Native
Pieter De Baets - An introduction to React NativePieter De Baets - An introduction to React Native
Pieter De Baets - An introduction to React Native
 
React-Native for multi-platform mobile applications @ Codemotion Rome 2017
React-Native for multi-platform mobile applications @ Codemotion Rome 2017React-Native for multi-platform mobile applications @ Codemotion Rome 2017
React-Native for multi-platform mobile applications @ Codemotion Rome 2017
 
A Closer Look At React Native
A Closer Look At React NativeA Closer Look At React Native
A Closer Look At React Native
 
Workshop 15: Ionic framework
Workshop 15: Ionic frameworkWorkshop 15: Ionic framework
Workshop 15: Ionic framework
 
React Native
React NativeReact Native
React Native
 
Intro to react native
Intro to react nativeIntro to react native
Intro to react native
 
React native: building native iOS apps with javascript
React native: building native iOS apps with javascriptReact native: building native iOS apps with javascript
React native: building native iOS apps with javascript
 
Intro To React Native
Intro To React NativeIntro To React Native
Intro To React Native
 
Build a lego app with CocoaPods
Build a lego app with CocoaPodsBuild a lego app with CocoaPods
Build a lego app with CocoaPods
 
React JS Belgium Touch Base - React, Flux, React Native
React JS Belgium Touch Base - React, Flux, React NativeReact JS Belgium Touch Base - React, Flux, React Native
React JS Belgium Touch Base - React, Flux, React Native
 
Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6
 
React js basics
React js basicsReact js basics
React js basics
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React Native
 
React Native - Workshop
React Native - WorkshopReact Native - Workshop
React Native - Workshop
 

En vedette

Reasoning about Code with React
Reasoning about Code with ReactReasoning about Code with React
Reasoning about Code with ReactJuan Maiz
 
CURRICULUM- PORTUGUESE 1
CURRICULUM- PORTUGUESE 1CURRICULUM- PORTUGUESE 1
CURRICULUM- PORTUGUESE 1wilson mateus
 
Technical report for toyota water tank 1
Technical report for toyota water tank 1Technical report for toyota water tank 1
Technical report for toyota water tank 1Alisa Chen
 
Empresa y calidad total
Empresa y calidad totalEmpresa y calidad total
Empresa y calidad totalLUISANA DUARTE
 
Aplicabilidade do monitoramento da biodiversidade à gestão
Aplicabilidade do monitoramento da biodiversidade à gestãoAplicabilidade do monitoramento da biodiversidade à gestão
Aplicabilidade do monitoramento da biodiversidade à gestãoRonaldo Weigand Jr
 
Museo Del Louvre
Museo Del LouvreMuseo Del Louvre
Museo Del LouvreJoaoldan
 
How to solve a problem with machine learning
How to solve a problem with machine learningHow to solve a problem with machine learning
How to solve a problem with machine learningAmendra Shrestha
 
חסידי אומות עולם
חסידי אומות עולםחסידי אומות עולם
חסידי אומות עולםomer sasoni
 
Led t8 tube light catalog
Led  t8 tube light catalogLed  t8 tube light catalog
Led t8 tube light catalogngtledcom
 
Tension members
Tension membersTension members
Tension memberssky hawk
 
El doble parte 1 jean pierre garnier malet
El doble   parte 1   jean pierre garnier maletEl doble   parte 1   jean pierre garnier malet
El doble parte 1 jean pierre garnier maletCleusa Vicchiarelli
 

En vedette (20)

Reasoning about Code with React
Reasoning about Code with ReactReasoning about Code with React
Reasoning about Code with React
 
Practica uno infor.
Practica uno infor.Practica uno infor.
Practica uno infor.
 
advanced
advancedadvanced
advanced
 
CURRICULUM- PORTUGUESE 1
CURRICULUM- PORTUGUESE 1CURRICULUM- PORTUGUESE 1
CURRICULUM- PORTUGUESE 1
 
Manejo de Internet
 Manejo de Internet Manejo de Internet
Manejo de Internet
 
Technical report for toyota water tank 1
Technical report for toyota water tank 1Technical report for toyota water tank 1
Technical report for toyota water tank 1
 
Empresa y calidad total
Empresa y calidad totalEmpresa y calidad total
Empresa y calidad total
 
Aplicabilidade do monitoramento da biodiversidade à gestão
Aplicabilidade do monitoramento da biodiversidade à gestãoAplicabilidade do monitoramento da biodiversidade à gestão
Aplicabilidade do monitoramento da biodiversidade à gestão
 
Sites
SitesSites
Sites
 
Museo Del Louvre
Museo Del LouvreMuseo Del Louvre
Museo Del Louvre
 
How to solve a problem with machine learning
How to solve a problem with machine learningHow to solve a problem with machine learning
How to solve a problem with machine learning
 
חסידי אומות עולם
חסידי אומות עולםחסידי אומות עולם
חסידי אומות עולם
 
Automatski - Smart Meter Solution
Automatski - Smart Meter SolutionAutomatski - Smart Meter Solution
Automatski - Smart Meter Solution
 
Led t8 tube light catalog
Led  t8 tube light catalogLed  t8 tube light catalog
Led t8 tube light catalog
 
Apostila Geologia - Pedologia - sol213
Apostila Geologia - Pedologia - sol213Apostila Geologia - Pedologia - sol213
Apostila Geologia - Pedologia - sol213
 
Reda cem 7.1
Reda cem 7.1Reda cem 7.1
Reda cem 7.1
 
Lista 7.2
Lista 7.2Lista 7.2
Lista 7.2
 
Agua nos solos
Agua nos solosAgua nos solos
Agua nos solos
 
Tension members
Tension membersTension members
Tension members
 
El doble parte 1 jean pierre garnier malet
El doble   parte 1   jean pierre garnier maletEl doble   parte 1   jean pierre garnier malet
El doble parte 1 jean pierre garnier malet
 

Similaire à The Gist of React Native

NativeScript: Cross-Platform Mobile Apps with JavaScript and Angular
NativeScript: Cross-Platform Mobile Apps with JavaScript and AngularNativeScript: Cross-Platform Mobile Apps with JavaScript and Angular
NativeScript: Cross-Platform Mobile Apps with JavaScript and AngularTodd Anglin
 
Universal Applications with Universal JavaScript
Universal Applications with Universal JavaScriptUniversal Applications with Universal JavaScript
Universal Applications with Universal JavaScriptThomas Joseph
 
Busy Developer's Guide to Windows 8 HTML/JavaScript Apps
Busy Developer's Guide to Windows 8 HTML/JavaScript AppsBusy Developer's Guide to Windows 8 HTML/JavaScript Apps
Busy Developer's Guide to Windows 8 HTML/JavaScript AppsJAX London
 
An Introduction to ReactNative
An Introduction to ReactNativeAn Introduction to ReactNative
An Introduction to ReactNativeMichał Taberski
 
Angular 2 and NativeScript
Angular 2 and NativeScriptAngular 2 and NativeScript
Angular 2 and NativeScriptJen Looper
 
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
 
HTML5 Can't Do That
HTML5 Can't Do ThatHTML5 Can't Do That
HTML5 Can't Do ThatNathan Smith
 
Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016Marco Breveglieri
 
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 startedsparkfabrik
 
Cross-platform mobile dev with Mono
Cross-platform mobile dev with MonoCross-platform mobile dev with Mono
Cross-platform mobile dev with MonoCraig Dunn
 
Plattformübergreifende App-Entwicklung (ein Vergleich) - MobileTechCon 2010
Plattformübergreifende App-Entwicklung (ein Vergleich) - MobileTechCon 2010Plattformübergreifende App-Entwicklung (ein Vergleich) - MobileTechCon 2010
Plattformübergreifende App-Entwicklung (ein Vergleich) - MobileTechCon 2010Heiko Behrens
 
Isomorphic JavaScript: #DevBeat Master Class
Isomorphic JavaScript: #DevBeat Master ClassIsomorphic JavaScript: #DevBeat Master Class
Isomorphic JavaScript: #DevBeat Master ClassSpike Brehm
 
Develop an app for Windows 8 using HTML5
Develop an app for Windows 8 using HTML5Develop an app for Windows 8 using HTML5
Develop an app for Windows 8 using HTML5Soumow Dollon
 
Rethinking Best Practices
Rethinking Best PracticesRethinking Best Practices
Rethinking Best Practicesfloydophone
 
Ample SDK: A tour de force
Ample SDK: A tour de forceAmple SDK: A tour de force
Ample SDK: A tour de forceSergey Ilinsky
 
Building Cross-Platform Mobile Apps
Building Cross-Platform Mobile AppsBuilding Cross-Platform Mobile Apps
Building Cross-Platform Mobile AppsTroy Miles
 
From Idea to App (or “How we roll at Small Town Heroes”)
From Idea to App (or “How we roll at Small Town Heroes”)From Idea to App (or “How we roll at Small Town Heroes”)
From Idea to App (or “How we roll at Small Town Heroes”)Bramus Van Damme
 
React js - The Core Concepts
React js - The Core ConceptsReact js - The Core Concepts
React js - The Core ConceptsDivyang Bhambhani
 

Similaire à The Gist of React Native (20)

NativeScript: Cross-Platform Mobile Apps with JavaScript and Angular
NativeScript: Cross-Platform Mobile Apps with JavaScript and AngularNativeScript: Cross-Platform Mobile Apps with JavaScript and Angular
NativeScript: Cross-Platform Mobile Apps with JavaScript and Angular
 
Universal Applications with Universal JavaScript
Universal Applications with Universal JavaScriptUniversal Applications with Universal JavaScript
Universal Applications with Universal JavaScript
 
Busy Developer's Guide to Windows 8 HTML/JavaScript Apps
Busy Developer's Guide to Windows 8 HTML/JavaScript AppsBusy Developer's Guide to Windows 8 HTML/JavaScript Apps
Busy Developer's Guide to Windows 8 HTML/JavaScript Apps
 
An Introduction to ReactNative
An Introduction to ReactNativeAn Introduction to ReactNative
An Introduction to ReactNative
 
Angular 2 and NativeScript
Angular 2 and NativeScriptAngular 2 and NativeScript
Angular 2 and NativeScript
 
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]
 
HTML5 Can't Do That
HTML5 Can't Do ThatHTML5 Can't Do That
HTML5 Can't Do That
 
Mobile native-hacks
Mobile native-hacksMobile native-hacks
Mobile native-hacks
 
Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016
 
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
 
Cross-platform mobile dev with Mono
Cross-platform mobile dev with MonoCross-platform mobile dev with Mono
Cross-platform mobile dev with Mono
 
Plattformübergreifende App-Entwicklung (ein Vergleich) - MobileTechCon 2010
Plattformübergreifende App-Entwicklung (ein Vergleich) - MobileTechCon 2010Plattformübergreifende App-Entwicklung (ein Vergleich) - MobileTechCon 2010
Plattformübergreifende App-Entwicklung (ein Vergleich) - MobileTechCon 2010
 
Isomorphic JavaScript: #DevBeat Master Class
Isomorphic JavaScript: #DevBeat Master ClassIsomorphic JavaScript: #DevBeat Master Class
Isomorphic JavaScript: #DevBeat Master Class
 
Develop an app for Windows 8 using HTML5
Develop an app for Windows 8 using HTML5Develop an app for Windows 8 using HTML5
Develop an app for Windows 8 using HTML5
 
Rethinking Best Practices
Rethinking Best PracticesRethinking Best Practices
Rethinking Best Practices
 
Ample SDK: A tour de force
Ample SDK: A tour de forceAmple SDK: A tour de force
Ample SDK: A tour de force
 
Building Cross-Platform Mobile Apps
Building Cross-Platform Mobile AppsBuilding Cross-Platform Mobile Apps
Building Cross-Platform Mobile Apps
 
From Idea to App (or “How we roll at Small Town Heroes”)
From Idea to App (or “How we roll at Small Town Heroes”)From Idea to App (or “How we roll at Small Town Heroes”)
From Idea to App (or “How we roll at Small Town Heroes”)
 
Fewd week4 slides
Fewd week4 slidesFewd week4 slides
Fewd week4 slides
 
React js - The Core Concepts
React js - The Core ConceptsReact js - The Core Concepts
React js - The Core Concepts
 

Dernier

Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 

Dernier (20)

Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 

The Gist of React Native

  • 1. THE GIST OF REACT-NATIVE What it is, Why you’d use it August 11, 2016 Darren Cruse darren.cruse@gmail.com
  • 2. This Talk is in Beta Expect Bugs and Possible Crashes send feedback to: darren.cruse@gmail.com
  • 3. (my journey thru UI development developments)
  • 4. About your speaker… • 51 years old (old old old so very old grim reaper get away from me!) • used various languages: asm, C, C++, Perl, Java, Groovy, Javascript • did desktop GUI programming before the web (Mac, Unix X Windows, Java Swing) • spent the last 13 years doing web applications • haven’t done any mobile apps in the app stores • I’m still learning react-native  
  • 5. My last 13 years doing web applications (too much code, esp. for so-so user experiences)
  • 6. And then this guy famously said about html5…
  • 7. This seemed part of a “meme”… The prevalent (though not universal) idea that: “To provide the best user experience you have to use native platform SDKs and languages, not cross platform tools and e.g. not the hybrid phonegap/cordova approach” *Apple’s early fights against flash on iOS, the restrictions against interpreted code, etc. seemed part of this “meme” as well.
  • 8. Was the Mobile Train Passing Me By?
  • 9. So I bought all the toys
  • 10. And started doing my homework…
  • 11. BUT OMG… Web apps during the day, and all this too?
  • 12. So I started a personal quest evaluating cross platform mobile tools on my weekends… Titanium RunRev LiveCode NativeScript Tabris.js JavaFX Adobe Flex Xamarin Lambda Native Qt Quick QML Famo.usjQuery Mobile Sencha
  • 13. But Mobile remained a side interest…
  • 14. (Nylas email client written in html/css with Electron) Then recently came some great html UIs
  • 15. (Atom editor written in html/css with Electron) Then recently came some great html UIs
  • 16. (Deco react-native IDE written in html/css with Electron - irony?) Then recently came some great html UIs
  • 17. So maybe html5 was underestimated? *Though I notice many of these great hybrid html based apps have an emphasis on *text* - maybe not a coincidence?
  • 18. And then I see stuff like this… https://yahoodevelopers.tumblr.com/post/127636051988/seven-years-into-the-mobile-revolution-content-is
  • 19. I’M SO CONFUSED!! (do I want to focus on web apps or on native apps?!)
  • 21. AND IT’S NO LONGER “WEB APPS OR NATIVE APPS”
  • 23. SO… REACT = USE YOUR WEB DEVELOPER SKILLS FOR WEB APPS (AS YOU’D EXPECT)
  • 24. AND: REACT-NATIVE = USE YOUR WEB DEVELOPER SKILLS FOR MOBILE APPS (BUT MINUS THE HTML)
  • 25. END OF STORY. MY QUEST HAS ENDED! (MAYBE?)
  • 26. BUT WAIT YOU SAY?
  • 27. DIDN’T YOU ALSO JUST MAKE A PITCH FOR: PHONEGAP/CORDOVA, IONIC, ELECTRON, ETC?
  • 28. SINCE THEY TOO LET YOU DEVELOP MOBILE APPS USING YOUR “WEB DEVELOPER SKILLS”?
  • 31. MY DEFINITIVE ANSWER: YES AND NO END OF STORY.
  • 32. MY DEFINITIVE ANSWER: YES AND NO END OF STORY. (KIDDING)
  • 33. The React-Native Folks would say this: Those other tools are fighting that “meme”. The meme that you *must* write mobile apps using native SDKs for the best possible user experience. We (the folks behind react-native) are not. *We* are truly native mobile apps without compromise!!
  • 34. More details: • React-native is truly claiming they are super close to the goal that you can write cross-platform apps that are indistinguishable to the user from those you wrote directly using the native sdks. • They say they rejected the idea (like from java) of “write once run anywhere” knowing that would lead to compromises for the user experience because the browser, iOS, and Android *are different*. They *do* have different “look and feels”, “style guides”, etc. • Their motto is “learn once write anywhere” meaning you learn the react programming model and apply that uniquely on each platform. • In practice this means having a lot of shared javascript code between your browser (react), iOS and Android (react-native) applications, but with a (hopefully) small amount of code (and UI markup) using the unique platform SDKs if and when needed.
  • 35. So what is this “React Programming Model”? (note: react as opposed to react-native) • HTML *in* your javascript Code (not a separate template) • React Components (i.e. “Custom Tags”) • Explicit definition and handling of “program state” • UI as a *function* of that state • No direct manipulation of the DOM • Because the framework *automatically* updates the UI for you
  • 36. HTML *in* your javascript Code = JSX (not a separate template) TodoApp.js /** @jsx React.DOM */ var React = require('react'); var TodoList = require('./TodoList'); class TodoApp { getInitialState () { return { allTodos: TodoStore.getAll() }; } render () { return ( <div> <Header /> <TodoList todos={this.state.allTodos} /> <Footer todos={this.state.allTodos} /> </div> ) } } module.exports = React.createClass(TodoApp.prototype); example code from: https://github.com/edvinerikson/ES6-TodoMVC-React curly braces escape out to javascript when inside JSX tags.
  • 37. React Components • i.e. “Custom Tags”. don’t just use html - invent your own tags! Similar (but incompatible) to Angular “Directives” and W3C Web Components https://facebook.github.io/react/docs/webcomponents.html TodoItem.js /** @jsx React.DOM */ var React = require('react'); var TodoItem = require('./TodoItem'); class TodoList { render () { return ( <section id="main"> <input id="toggle-all" type="checkbox" /> <label htmlFor="toggle-all">Mark all as completed</label> <ul id="todo-list"> {this.props.todos.toJSON().map((todo) => { return <TodoItem key={todo.id} todo={todo} /> })} </ul> </section> ) } } module.exports = React.createClass(TodoList.prototype); TodoList.js /** @jsx React.DOM */ var React = require('react'); class TodoItem { // stuff (omitted for brevity) } module.exports = React.createClass(TodoItem.prototype); note the components are just CommonJS modules
  • 38. Explicit definition and handling of “program state” /** @jsx React.DOM */ var React = require('react'); var TodoTextInput = require('./TodoTextInput'); class TodoItem { getInitialState () { return {isEditing: false} } render () { let todo = this.props.todo; let input; if(this.state.isEditing) { input = <TodoTextInput className="edit" onSave={this.setState({isEditing: false})} value={todo.title} /> } return ( <li className={cx({'completed': todo.completed,'editing': this.state.isEditing})} key={todo.id}> <div className="view"> <input className="toggle" type="checkbox" checked={todo.completed} onChange={this._onToggleComplete} /> <label onDoubleClick={this._onDoubleClick}> {todo.title} </label> <button className="destroy" onClick={this._onDestroyClick} /> </div> {input} </li> ) } }
  • 39. UI as a function of that state UI = f(state) /** @jsx React.DOM */ var React = require('react'); var TodoTextInput = require('./TodoTextInput'); class TodoItem { getInitialState () { return {isEditing: false} } render () { let todo = this.props.todo; let input; if(this.state.isEditing) { input = <TodoTextInput className="edit" onSave={this.setState({isEditing: false})} value={todo.title} /> } return ( <li className={cx({'completed': todo.completed,'editing': this.state.isEditing})} key={todo.id}> <div className="view"> <input className="toggle" type="checkbox" checked={todo.completed} onChange={this._onToggleComplete} /> <label onDoubleClick={this._onDoubleClick}> {todo.title} </label> <button className="destroy" onClick={this._onDestroyClick} /> </div> {input} </li> ) } }
  • 40. "No direct manipulation of the DOM” and "the framework automagically updates the UI for you" • You’re using the react “Virtual DOM” (what JSX is transpiled into). Note this can run under node just fine (e.g. for server side rendering). • React internally uses “DOM Diffing” to identify and update only the parts of the DOM that really need to change. diagram from: https://www.infoq.com/articles/react-native-introduction
  • 41. HOW’S THIS DIFFERENT IN REACT-NATIVE?
  • 42. THE KEY DIFFERENCE: THERE IS NO BROWSER AND SO THERE IS NO BROWSER DOM
  • 43. For the programmer: it’s almost the same • It’s just that instead of html tags we now have tags corresponding to native widgets • So in react-native the “DOM Diffing” plumbing is replaced with code that renders UI using native widget SDKs. diagram from: https://www.infoq.com/articles/react-native-introduction
  • 44. The “Bridge” • The Bridge allows asynchronous calling from JS to Native and from Native to JS. Likewise native events are sent to the JS event handlers. • JSON messages are passed • These run in different threads - usually on the one mobile device • But you can also run the JS in chrome over a websocket in order to live edit and even use the chrome debugger against your running mobile app - this is a great developer experience(!!) diagram from: https://www.infoq.com/articles/react-native-introduction Javascript VM Native Code
  • 45. Regarding The “Developer Experience”: Here’s the Developer Menu (this appears when you “shake gesture” your app)
  • 46. An example of Debugging JS in Chrome
  • 47. You can use “.ios.js” and “.android.js” extensions (though you don’t often need to) example code from: https://github.com/thebakeryio/todomvc-react-native render() { return ( <View style={ styles.container }> { Platform.OS === 'ios' ? <AddTodoItem /> : null } <MainNavigation /> </View> ); } Or you can also look at “Platform.OS” within your “generic” code files:
  • 48. Some example code (part of the ios file from the previous slide) index.ios.jsclass MainNavigation extends Component { render() { const children = mainNavigation.routes.map( (tab, i) => { return ( <TabBarIOS.Item key={tab.key} icon={tab.icon} selectedIcon={tab.selectedIcon} title={tab.title} onPress={ () => dispatch(jumpTo(i, mainNavigation.key)) } selected={this.props.mainNavigation.index === i}> { this._renderTabContent(tab) } </TabBarIOS.Item> ); }); return ( <TabBarIOS> {children} </TabBarIOS> ); } _renderTabContent(tab) { return ( <View style={ styles.container }> <TodoList filter={tab.key} /> </View> ); } }
  • 49. Some example code (part of the android file from the previous slide) index.android.jsclass MainNavigation extends Component { render() { return ( <DrawerLayoutAndroid ref={(drawer) => { this.drawer = drawer; }} drawerWidth={300} drawerPosition={DrawerLayoutAndroid.positions.Left} renderNavigationView={this._renderNavigation.bind(this)}> {this._renderContent()} </DrawerLayoutAndroid> ); } _renderTabContent(tab) { return ( <View style={ styles.container }> <TodoList filter={tab.key} /> </View> ); } _renderContent() { return ( <View style={ styles.container }> <ToolbarAndroid style={androidToolbarStyle} navIcon={navigationIcon} onIconClicked={() => this.drawer.openDrawer()} title={selectedTab.title} /> <AddTodoItem /> {this._renderTabContent(selectedTab)} </View> ); } } note some of the top level nav components differ between iOS and android but our “TodoList” component does not.
  • 50. CSS is supported, with Flexbox for layout (but the CSS is done in javascript) index.ios.js import { StyleSheet } from 'react-native'; export default StyleSheet.create({ container: { flex: 1 }, header: { fontSize: 50, textAlign: 'center', color: 'rgba(175, 47, 47, 0.15)', marginTop: 50, marginBottom: 100 }, navigationMenuItem: { borderBottomWidth: StyleSheet.hairlineWidth, borderBottomColor: '#ededed', flexDirection: 'row', paddingTop: 15, paddingBottom: 15, paddingLeft: 15 }, label: { fontSize: 24, marginLeft: 10 } }); in this case the styles have been put in their own module so both the iOS and Android versions could use them. Since it’s just javascript sometimes it’s just in the component’s module file with the rest. import styles from ‘./styles'; (other stuff then…) _renderTabContent(tab) { return ( <View style={ styles.container }> <TodoList filter={tab.key} /> </View> ); } styles.js
  • 52. React-Native is still young (yet it’s being used anyway) • Current (as of August 2016) version is 0.32 • Only iOS and Android are officially supported by Facebook • Outside projects are in development for using React-Native to build: •Windows “Universal Apps” •Mac OS X desktop apps •Ubuntu Desktop Apps •AppleTV Apps •Samsung Tizen SmartTV/SmartWatch Apps
  • 53. And for some of you… A React Native renderer for Angular 2 http://angularjs.blogspot.com/2016/04/angular-2-react-native.html
  • 54. List of production apps: https://facebook.github.io/react-native/showcase.html
  • 55. React Native Job Market (Aug 2016) # of jobs searching indeed.com for “react native” California: 78 New York: 26 Pennsylvania 23 Texas: 22 Washington State: 14 Illinois: 11 Missouri: 1 note: many of the above are not *directly* react-native projects, but show because they list it as a “nice to have”.
  • 57. Some Tips • instructions at: https://facebook.github.io/react-native/docs/getting-started.html • for developing for android: you can use windows, linux, or Mac as your development machine • for developing for iOS: you have to have a Mac for your development machine. in fact I had trouble with react-native on an older Mac running Mavericks - I actually upgraded to El Capitan just for react- native. (I don’t now if this has been reported by others but just a warning FYI)
  • 60. easier to remember: http://www.reactnative.com docs link on the left goes to facebook site
  • 61. Books
  • 62. React-Native Themes and Starter Kits… https://strapmobile.com googling shows up quite a few both free and commercial… The one to the right is called “Native Starter Kit” (click image for animation)
  • 63. “Native Starter Kit Flat Theme” https://strapmobile.com just another example… (click image for animation)
  • 64. Theme Example: Material Design https://github.com/binggg/MaterialReactNative again - just an example (there’s even multiple Material Design projects)
  • 65. Caveats (It’s not all wine and roses!) Note react-native is building and deploying full android and iOS apps using all the same build and deployment tools that a natively written app would use. As I put slides away and went back to trying some code examples, I was hitting some errors running various examples written for older and/or newer versions of react-native than the one I have installed on my machine. Maybe I need to learn how to properly upgrade react-native and/or projects to work with newer versions of react-native, or maybe this is an area for improvement in react-native as it matures. Debugging the errors (e.g. java compilation errors) benefitted from having a little java/ android or iOS development experience. It makes me think at a serious company targeting browser, android, and iOS they will benefit greatly from an android developer and an iOS developer. Even if the rest of the team are javascript developers. It could still be *one team* so it’s much better than the alternative of having *three* teams. But it’s not all wine and roses (this is different than typical browser development!).
  • 66. RESOURCES Most but not all repeated from the previous slides but: https://facebook.github.io/react-native/ http://www.reactnative.com https://facebook.github.io/react-native/showcase.html https://react.parts/native https://strapmobile.com https://github.com/binggg/MaterialReactNative http://shop.oreilly.com/product/0636920041511.do https://www.packtpub.com/application-development/getting-started-react-native
  • 67. THANKS (AND AS BRENDON EICH SAYS…)