Dopo il successo del paradigma di React nello sviluppo web, l'azienda del più grande social network traspone lo stesso approccio per lo sviluppo mobile. React Native è un framework pensato per scrivere applicazioni mobile native scrivendo componenti React. Vedremo come questo si tramuti in un'opportunità per sviluppatori web e nativi, e le differenze con le soluzioni "ibride" viste fino ad oggi.
9. @matteomanchi
Matteo Manchi
} CEO at Impronta Advance
} Full stack developer
} React enthusiast
} Co-founder of RomaJS
} Maintainer of italia/design-react
} @matteomanchi
} https://github.com/takeno
9
About Me
15. @matteomanchi
React is a JavaScript library
for building user interfaces
developed by Facebook.
It allows you to define your UI using Components, which are
reusable, and it helps UI updates through Declarative UI.
All this overhead is minimized by Virtual DOM.
15
What is React?
16. @matteomanchi
■ Component: Everything is a component
■ Props: some data passed to child component
■ State: some internal data of a component
■ JSX: XML-like syntax helps to define component's
structure
■ Virtual DOM: tree of custom objects representing a port
of the DOM
16
Some keywords
23. @matteomanchi
A framework for building native apps using React.
23
React Native
Yeah, the same React of web developers
Learn once, write anywhere.
24. @matteomanchi
■ Summer 2013: React Native started as project in
Facebook’s internal hackaton
■ January 2015: During the React.js-conf, React Native first
public demo was shown
■ March 2015: React Native has been published as open
source project.
A brief history of React Native
24
26. @matteomanchi
■ Summer 2013: React Native started as project in
Facebook’s internal hackaton
■ January 2015: During the React.js-conf, React Native first
public demo was shown
■ March 2015: React Native has been published as open
source project.
■ May 2016: search terms of React Native surpassed iOS
and Android development, according to Google Trends
A brief history of React Native
26
27. @matteomanchi
React Native component
27
import React, { Component } from 'react';
import { Text } from 'react-native';
class SampleApp extends Component {
render() {
return (
<Text style={{margin: 40}}>Hello World!</Text>
);
}
}
29. @matteomanchi
■ npm install -g create-react-native-app
■ create-react-native-app MyNativeApp
■ cd MyNativeApp
■ npm start
■ Install Expo app for Android and iOS
■ Connect your device
29
Getting started
30. @matteomanchi
■ React-native-based company in Palo Alto
■ Huge contribution to React Native
■ Maintainers of create-react-native-app
■ Expo SDK
■ XDE
■ snack.expo.io
30
31. @matteomanchi 31
How it works
Native Bridge
Your code
JavaScript Core
bundle.js
Native View
render
32. @matteomanchi
React renders your entire app as a plain object, totally
decoupled from DOM. On every change, it performs the diff
of previous object tree with the new one. Then it change only
the partial DOM which is mutated.
32
Virtual DOM
<div>
Hello {this.props.name}
</div>
Js-plain version
JSX
Transpiler
Object Tree
react
engine
DOM
react-dom
engine
34. @matteomanchi 34
From Virtual DOM to Native
<Text>
Hello {this.props.name}
</Text>
Js-plain version
JSX
Transpiler
Object Tree
react
engine
Native
react-native
engine
37. @matteomanchi
Style
37
■ CSS-like declarations with camel-case properties
■ style props defined for all native components
■ It can be an array of styles
■ StyleSheet module to create multiple classes in one place
and cache them
It supports Flexbox!
41. @matteomanchi
React Native have useful tools to improve your
development experience.
How to show Dev Menu?
■ Shaking your device
■ Cmd + D on iOS Simulator
■ F2 on android emulator
41
Developer Tools
42. @matteomanchi
It reloads the js code, so you
can see changes without
recompile the entire app.
■ Cmd + R on iOS Simulator
■ Type r twice on android
emulator
42
Developer Tools - Reload
43. @matteomanchi
You can speed up your development times by having your
app reload automatically any time your code changes.
To do this, enable Live Reload from dev menu.
43
Developer Tools - Live Reload
44. @matteomanchi
You may even go a step further and keep your app running as new versions of
your files are injected into the JavaScript bundle automatically by enabling Hot
Reloading from the Developer Menu. This will allow you to persist the app's state
through reloads.
44
Developer Tools - Hot Reloading
46. @matteomanchi
In-app errors are displayed in a full screen alert with a red background inside your
app. This screen is known as a RedBox.
Instead, warnings will be displayed on screen with a yellow background. These
alerts are known as YellowBoxes.
46
Developer Tools - Yellow and Red boxes
47. @matteomanchi
You can inspect native views as you do with browser inspector.
Install react-dev-tool to connect automatically to your app.
47
Developer Tools - React Dev Tools
49. @matteomanchi
Create React Native App hides native projects folder and
uses Expo app to let you work on your own app without
need to build.
■ Like in create-react-app, eject is the process of setting up
your own custom build for your app.
■ When I need to do it?
■ I want to include external native libraries
■ I want to write my custom native module
■ I want to publish my app to Stores.
You can back to standard setup any time with:
npm run eject
This process is not reversible.
Back to native projects
49
51. @matteomanchi
React Native’s community is very active
■ 56k+ stars on Github
■ 10k+ issue solved
■ React Native Community on Github
51
React Native Ecosystem
52. @matteomanchi 52
React Native Ecosystem
■ UI Components
● native-base
● react-native-elements
● react-native-material-kit
● react-native-material-design
■ Navigation
● react-native-router-flux
● react-navigation
● native-navigation by AirBnB
● wix/react-native-navigation
Hundreds of packages published:
■ Native API
● react-native-maps by AirBnB
● react-native-camera
● react-native-onesignal
● code-push by Microsoft
53. @matteomanchi
Facebook Ads Manager
53
Where is used React Native?
85% shared code between platforms
https://code.facebook.com/.../react-native-how-we-built-the-first-cross-platform
54. @matteomanchi 54
Where is used React Native?
Facebook App
FB event section is in RN
http://goo.gl/ziBzOl
55. @matteomanchi 55
Who is using React Native?
Facebook Facebook
Ads Manager
Instagram AirBnB
Skype Tesla Wallmart Discord