Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 550b685

Browse files
author
Will Anderson
committed
Add recipe for optional update button
1 parent e0b3c09 commit 550b685

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

Recipes/UpdateButton.ios.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
'use strict';
2+
3+
var pkg = require('./package');
4+
var React = require('react-native');
5+
var {
6+
AppRegistry,
7+
StyleSheet,
8+
Text,
9+
View,
10+
} = React;
11+
var Button = require('react-native-button');
12+
13+
var CodePush = require('react-native-code-push');
14+
15+
var UpdateButton = React.createClass({
16+
getInitialState: function() {
17+
return {};
18+
},
19+
componentDidMount: function() {
20+
CodePush.checkForUpdate().done((update) => {
21+
if (update && !update.downloadURL) {
22+
this.setState({
23+
update: update
24+
});
25+
}
26+
});
27+
},
28+
update: function() {
29+
this.state.update.download().done((newPackage) => {
30+
newPackage.apply();
31+
});
32+
},
33+
render: function() {
34+
var updateButton = null;
35+
if (this.state.update) {
36+
updateButton = <Button onPress={this.update}>Update</Button>;
37+
}
38+
39+
return (
40+
<View style={styles.container}>
41+
<Text>
42+
Welcome to {pkg.name} {pkg.version}!
43+
</Text>
44+
{updateButton}
45+
</View>
46+
);
47+
}
48+
});
49+
50+
var styles = StyleSheet.create({
51+
container: {
52+
flex: 1,
53+
justifyContent: 'center',
54+
alignItems: 'center',
55+
backgroundColor: '#F5FCFF',
56+
}
57+
});
58+
59+
AppRegistry.registerComponent('UpdateButton', () => UpdateButton);

0 commit comments

Comments
 (0)