Nader Dabit
Teaching and building apps using React and React Native
Nader Dabit
Framework for building Native Mobile Apps using JavaScript
<div>
<p>Hello World</p>
</div>
<View>
<Text>Hello World</Text>
</View>
HTML
React Native
HTML | React Native
<div> == <View>
<p> || <span> == <Text>
<button> == <TouchableHighlight>
<img /> == <Image />
<input /> == <TextInput />
import React from "react"
class SomeComponent extends React.Component {
render () {
return (
<div>
<p>Hello World</p>
</div>
)
}
}
React
import React from "react"
import { View, Text } from "react-native"
class SomeComponent extends React.Component {
render () {
return (
<View>
<Text>Hello World</Text>
</View>
)
}
}
React Native
import { Button, SocialIcon } from "react-native-elements"
<Button
title="Button" />
<SocialIcon
type="facebook" />
Pros
Cons
These people think so
Can currently target Android, iOS and Windows
In development to target MacOS, Web, Apple TV, Tizen
Compiles this:
<div>
<span>Hello World</span>
</Div>
To this:
<View>
<Text>Hello World</Text>
</View>
Fundamental changes in the way future engineered teams are designed and organized.
(beta)
Cross stack engineering is an opportunity that is blossoming with React Native
- James Ide, Engineer at Exponent
Team × Technology React Conf 2016
(beta)
Because Native development is becoming more and more expensive, engineers who can deliver applications across platforms and stacks will become extremely valuable and in demand.
Main stumbling blocks
Routing / Navigation
Routing / Navigation - React
const App = () => (
<Router>
<Match exactly pattern="/" component={Home} />
<Match pattern="/about" component={About} />
<Match pattern="/topics" component={Topics} />
<Miss component={NoMatch}/>
</Router>
)
Routing / Navigation - Angular
$routeProvider
.when("/", {
templateUrl : "main.htm"
})
.when("/red", {
templateUrl : "red.htm"
})
.when("/blue", {
templateUrl : "blue.htm"
});
import React from "react"
import { Navigator } from "react-native"
import Component1 from "./Component1"
class App extends React.Component {
renderScene (route, navigator) {
return <route.component />
}
render () {
return (
<Navigator
renderScene={this.renderScene}
initialRoute={{
component: Component1
}} />
)
}
}
Routing / Navigation - React-Native
Navigating between scenes - React-Native
Navigating between scenes web
<a href="/somepath">Click Me</a>
// import component
import Component2 from "./Component2"
// create navigation method
navigate () {
navigator.push({ component: Component2 })
}
// handle click
<Button
title="Click Me"
onPress={this.navigate}
/>
navigator.push({
component: Component2
})
Route array
[ {component: Component1} ]
Push route
Route array
[ {component: Component1}, {component: Component2} ]
navigator.pop()
Pop route
Route array
[ {component: Component1} ]
navigator.push({
component: Component2,
name: 'NorthEast JavaScript Conference',
location: 'Connecticut'
})
Rendering a scene
renderScene (route, navigator) {
if (route.location === 'Connecticut') {
// do some logic, return different component
}
return <route.component title={route.name} />
}
Everything is a property of the route
[
{component: Component1},
{component: Component2, location: 'Connecticut', name: 'NEJSConf'}
]
Route array
Navigation - Getting Started
Explore different router Apis, choose one that makes sense to you
Styling React Native
// css
.header {
width: 100%;
background-color: red
}
// html
<div class="header" />
// styles variable
styles = {
header: {
width '100%',
backgroundColor: 'red'
}
}
// style
<div style={styles.header} />
// styles variable
styles = StyleSheet.create({
header: {
width '100%',
backgroundColor: 'red'
}
})
// style
<View style={styles.header} />
In web development, we reuse classes:
// css
.button {
background-color: blue;
}
// html
<div>
<button class='button'>Button1</button>
<button class='button'>Button1</button>
<button class='button'>Button1</button>
</div>
In React / React Native, we reuse components:
const Button = () => (
<TouchableHighlight style={styles.button}>
<Text style={styles.buttonText}>Hello World</Text>
</TouchableHighlight>
)
export default Button
import Button from './Button'
import React from 'react'
import { View } from 'react-native'
class Home extends React.Component {
render () {
return (
<View>
<Button />
<Button />
<Button />
</View>
)
}
}
Get a quick start by using UI Libraries, like bootstrap for the web.
React Elements
Get a quick start by using UI Libraries, like bootstrap for the web.
React Native Material Design
Get a quick start by using UI Libraries, like bootstrap for the web.
Shoutem UI
Have node installed, then:
npm install -g react-native-cli
react-native init ProjectName
cd ProjectName
react-native run-ios
react-native run-android
Writing an Exponent app is like writing a React Native app, except you never need to open Xcode / Android Studio
Entire environment is installed for you, with exception of Simulators
Getting Started
Creating New Project with Exponent
Working with New Project in Exponent
Working with New Project in Exponent
Working with New Project in Exponent
By Nader Dabit
For Northeast Javascript Conference