Files
react-native-code-push/Recipes/UpdateButton.ios.js
Geoffrey Goh a97407508b updated sync
2015-11-17 18:24:56 -08:00

60 lines
1.2 KiB
JavaScript

'use strict';
var pkg = require('./package');
var React = require('react-native');
var {
AppRegistry,
StyleSheet,
Text,
View,
} = React;
var Button = require('react-native-button');
var CodePush = require('react-native-code-push');
var UpdateButton = React.createClass({
getInitialState: function() {
return {};
},
componentDidMount: function() {
CodePush.checkForUpdate().done((update) => {
if (update && !update.downloadURL) {
this.setState({
update: update
});
}
});
},
update: function() {
this.state.update.download().done((newPackage) => {
newPackage.install();
});
},
render: function() {
var updateButton = null;
if (this.state.update) {
updateButton = <Button onPress={this.update}>Update</Button>;
}
return (
<View style={styles.container}>
<Text>
Welcome to {pkg.name} {pkg.version}!
</Text>
{updateButton}
</View>
);
}
});
var styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
}
});
AppRegistry.registerComponent('UpdateButton', () => UpdateButton);