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

Commit 49f6f67

Browse files
author
Will Anderson
committed
Merge pull request #12 from Microsoft/recipes
Recipes
2 parents b749242 + 550b685 commit 49f6f67

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-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);

Recipes/UpdateOnStart.ios.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
12+
var CodePush = require('react-native-code-push');
13+
14+
var UpdateOnStart = React.createClass({
15+
componentDidMount: function() {
16+
CodePush.checkForUpdate().done((update) => {
17+
if (update && update.downloadUrl) {
18+
update.download().done((newPackage) => {
19+
newPackage.apply();
20+
});
21+
}
22+
});
23+
},
24+
render: function() {
25+
return (
26+
<View style={styles.container}>
27+
<Text>
28+
Welcome to {pkg.name} {pkg.version}!
29+
</Text>
30+
</View>
31+
);
32+
}
33+
});
34+
35+
var styles = StyleSheet.create({
36+
container: {
37+
flex: 1,
38+
justifyContent: 'center',
39+
alignItems: 'center',
40+
backgroundColor: '#F5FCFF',
41+
}
42+
});
43+
44+
AppRegistry.registerComponent('UpdateOnStart', () => UpdateOnStart);

0 commit comments

Comments
 (0)