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

Commit 6d2abd1

Browse files
author
Richard Hua
authored
Merge pull request #537 from Microsoft/upgrade-example-app
Upgrade example app
2 parents 7033ef7 + 3090ef0 commit 6d2abd1

File tree

7 files changed

+264
-24
lines changed

7 files changed

+264
-24
lines changed

Examples/CodePushDemoApp/.flowconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[ignore]
22

33
# We fork some components by platform.
4-
.*/*[.]android.js
4+
.*/*.android.js
55

66
# Ignore templates with `@flow` in header
77
.*/local-cli/generator.*

Examples/CodePushDemoApp/demo.js

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import {
1111

1212
import CodePush from "react-native-code-push";
1313

14+
/**
15+
* Configured with a MANUAL check frequency for easy testing. For production apps, it is recommended to configure a
16+
* different check frequency, such as ON_APP_START, for a 'hands-off' approach where CodePush.sync() does not
17+
* need to be explicitly called. All options of CodePush.sync() are also available in this decorator.
18+
*/
1419
@CodePush({ checkFrequency: CodePush.CheckFrequency.MANUAL })
1520
class CodePushDemoApp extends Component {
1621
constructor() {
@@ -39,7 +44,7 @@ class CodePushDemoApp extends Component {
3944
this.setState({ syncMessage: "Update cancelled by user.", progress: false });
4045
break;
4146
case CodePush.SyncStatus.UPDATE_INSTALLED:
42-
this.setState({ syncMessage: "Update installed.", progress: false });
47+
this.setState({ syncMessage: "Update installed and will be applied on restart.", progress: false });
4348
break;
4449
case CodePush.SyncStatus.UNKNOWN_ERROR:
4550
this.setState({ syncMessage: "An unknown error occurred.", progress: false });
@@ -59,12 +64,28 @@ class CodePushDemoApp extends Component {
5964
this.setState({ restartAllowed: !this.state.restartAllowed });
6065
}
6166

67+
getUpdateMetadata() {
68+
CodePush.getUpdateMetadata(CodePush.UpdateState.RUNNING)
69+
.then((metadata: LocalPackage) => {
70+
this.setState({ syncMessage: metadata ? JSON.stringify(metadata) : "Running binary version", progress: false });
71+
}, (error: any) => {
72+
this.setState({ syncMessage: "Error: " + error, progress: false });
73+
});
74+
}
75+
76+
/** Update is downloaded silently, and applied on restart (recommended) */
6277
sync() {
6378
CodePush.sync(
64-
{
65-
installMode: CodePush.InstallMode.IMMEDIATE,
66-
updateDialog: true
67-
},
79+
{},
80+
this.codePushStatusDidChange.bind(this),
81+
this.codePushDownloadDidProgress.bind(this)
82+
);
83+
}
84+
85+
/** Update pops a confirmation dialog, and then immediately reboots the app */
86+
syncImmediate() {
87+
CodePush.sync(
88+
{ installMode: CodePush.InstallMode.IMMEDIATE, updateDialog: true },
6889
this.codePushStatusDidChange.bind(this),
6990
this.codePushDownloadDidProgress.bind(this)
7091
);
@@ -85,14 +106,20 @@ class CodePushDemoApp extends Component {
85106
Welcome to CodePush!
86107
</Text>
87108
<TouchableOpacity onPress={this.sync.bind(this)}>
88-
<Text style={styles.syncButton}>Start Sync!</Text>
109+
<Text style={styles.syncButton}>Press for background sync</Text>
110+
</TouchableOpacity>
111+
<TouchableOpacity onPress={this.syncImmediate.bind(this)}>
112+
<Text style={styles.syncButton}>Press for dialog-driven sync</Text>
89113
</TouchableOpacity>
90-
<Text style={styles.messages}>{this.state.syncMessage || ""}</Text>
91114
{progressView}
92115
<Image style={styles.image} resizeMode={Image.resizeMode.contain} source={require("./images/laptop_phone_howitworks.png")}/>
93116
<TouchableOpacity onPress={this.toggleAllowRestart.bind(this)}>
94117
<Text style={styles.restartToggleButton}>Restart { this.state.restartAllowed ? "allowed" : "forbidden"}</Text>
95118
</TouchableOpacity>
119+
<TouchableOpacity onPress={this.getUpdateMetadata.bind(this)}>
120+
<Text style={styles.syncButton}>Press for Update Metadata</Text>
121+
</TouchableOpacity>
122+
<Text style={styles.messages}>{this.state.syncMessage || ""}</Text>
96123
</View>
97124
);
98125
}
@@ -106,11 +133,12 @@ const styles = StyleSheet.create({
106133
paddingTop: 50
107134
},
108135
image: {
109-
marginTop: 50,
136+
margin: 30,
110137
width: Dimensions.get("window").width - 100,
111138
height: 365 * (Dimensions.get("window").width - 100) / 651,
112139
},
113140
messages: {
141+
marginTop: 30,
114142
textAlign: "center",
115143
},
116144
restartToggleButton: {
@@ -124,7 +152,7 @@ const styles = StyleSheet.create({
124152
welcome: {
125153
fontSize: 20,
126154
textAlign: "center",
127-
margin: 10
155+
margin: 20
128156
},
129157
});
130158

0 commit comments

Comments
 (0)