Files
react-native-code-push/Examples/CodePushDemoApp/index.ios.js
Geoffrey Goh 28fc990e4f formatting
2015-11-12 20:45:40 -08:00

91 lines
2.0 KiB
JavaScript

/**
* Sample React Native App
* https://github.com/facebook/react-native
*/
'use strict';
var React = require('react-native');
var {
AppRegistry,
StyleSheet,
Text,
TouchableOpacity,
View,
} = React;
var Button = require("react-native-button");
var CodePush = require('react-native-code-push');
var CodePushDemoApp = React.createClass({
componentDidMount: function() {
this.checkUpdate();
},
checkUpdate: function() {
CodePush.checkForUpdate().done((update) => {
this.setState({ update: update });
});
CodePush.notifyApplicationReady().done();
},
getInitialState: function() {
return { update: false };
},
handlePress: function() {
this.state.update.download((progress) => {
this.setState({
progress:progress
});
}).done((localPackage) => {
localPackage.apply().done();
});
},
render: function() {
var updateView;
if (this.state.progress) {
updateView = (
<Text>{this.state.progress.receivedBytes} of {this.state.progress.totalBytes} bytes received</Text>
);
} else if (this.state.update) {
updateView = (
<View>
<Text>Update Available: {'\n'} {this.state.update.scriptVersion} - {this.state.update.description}</Text>
<Button style={{color: 'green'}} onPress={this.handlePress}>
Update
</Button>
</View>
);
};
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to Code Push!
</Text>
{updateView}
</View>
);
}
});
var styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
AppRegistry.registerComponent('CodePushDemoApp', () => CodePushDemoApp);