Life on the bleeding edge
This meme-free presentation brought to you by:
github.com/adamterlson
@adamterlson
slides.com/adamterlson
We're hiring JS folk!
adam.terlson@gmail.com
skype adam.terlson.internations
Titanium (compiles JS... yuck)
NativeScript (lacks framework, Angular WIP)
22,266
React Native
Since March
Bonus: Code Push
~5 mins
<App>
<TitleBar>
<LeftButton />
<ScreenTitle />
<RightButton />
</TitleBar>
<Content>
<TodoList>
<TodoItem />
<TodoItem />
<TodoItem />
</TodoList>
</Content>
</App>
class MyClass extends React.Component {
constructor(props) {
super(props);
this.state = {
// Initial State
};
}
_onSomething() {
this.setState( ... ); // New State
}
render() {
return (...); // Refresh button
}
}
class MyParent extends React.Component {
render() {
return (
<MyChild
item={this.props.item}
doSomething={() => this._doSomething() } />
);
}
}
class MyChild extends React.Component {
constructor(props) {
// props.item & props.doSomething
}
}
// e.g. React for Web
class MyParent extends React.Component {
render() {
// This does NOT return HTML
return (
<div className={this.state.jazz}>
<MyFirstChild>{this.state.foo}</MyFirstChild>
<MySecondChild bar={this.state.bar} />
</div>
);
}
}
Components
Virtual DOM
Real DOM
JavaScript
Native
Bridge
(Async)
On Device
Multi-threaded
Of varying degrees of completeness....
MyImage.png -> MyImage (image set)
1) Check NPM
2) Write your own
Components
Virtual "Stuff"
Real "Stuff"
let React = require('react-native');
let {
PushNotificationIOS
} = React;
PushNotificationIOS.scheduleLocalNotification({
fireDate: SomeDate,
alertBody: 'Hello there.'
});
// JS
static scheduleLocalNotification(details: Object) {
RCTPushNotificationManager.scheduleLocalNotification(details);
}
// ObjC
RCT_EXPORT_METHOD(scheduleLocalNotification:(UILocalNotification *)notification)
{
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
Inline
<View style={{ backgroundColor: 'red' }} />
let { StyleSheet } = require('react-native');
let styles = StyleSheet.create({
myThing: {
backgroundColor: 'red',
borderWidth: 1,
borderColor: 'rgba(255,255,255,0.5)',
paddingVertical: 10
}
});
With StyleSheet
<View style={styles.myThing} />
Multiple Styles
Last definition wins (think Object.assign)
<View style={[
styles.myThing,
{ backgroundColor: 'blue' }
]} />
Conditional Classes
<View style={[
styles.myThing,
state.active && styles.myThingActive
state.foo === 'foo' ?
styles.myThingFoo :
styles.myThingNotFoo
]} />
let React = require('react-native');
let { StyleSheet } = React;
let gutter = 10;
let green = 'green';
module.exports = StyleSheet.create({
titleContainer: {
height: 50
},
titleText: {
fontSize: 20,
fontFamily: 'Helvetica',
color: green
},
centerXY: {
justifyContent: 'center',
alignItems: 'center',
},
spacedVertical: {
marginVertical: gutter
}
});
<View style={[
styles.titleContainer,
styles.centerXY,
styles.spacedVertical]}>
<Text style={styles.titleText}>
Title
</Text>
</View>
let React = require('react-native');
let { StyleSheet } = React;
let gutter = 10;
let green = 'green';
let u = {
centerXY: {
justifyContent: 'center',
alignItems: 'center',
},
spacedVertical: {
marginVertical: gutter
}
};
let text = {
h1: {
fontSize: 20,
fontFamily: 'Helvetica'
}
};
module.exports = StyleSheet.create({
titleContainer: {
height: 40,
...u.centerXY,
...u.spacedVertical
},
titleText: {
color: green,
...text.h1
}
});
<View style={styles.titleContainer}>
<Text style={styles.titleText}>
Title
</Text>
</View>
Good article (and image source):
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
JavaScript
Native Stuff
UI, APIs, etc
Bridge
(Async)
Simulator or Device
Chrome Debugger
LIES
Maybe Angular + NativeScript?
github.com/adamterlson
adam.terlson@gmail.com