-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
123 lines (112 loc) · 3.38 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import { Alert, StyleSheet, Text, View, } from 'react-native';
import CodePush from 'react-native-code-push';
type Props = {};
export default class App extends Component<Props> {
constructor(props) {
super(props);
this.state = {
syncMessage: '有更新',
};
}
componentWillMount() {
this.CodePushUpdate();
}
CodePushUpdate = () => {
CodePush.sync({
// 有弹窗模式
// updateDialog: {
// appendReleaseDescription: true,
// descriptionPrefix: '更新内容:\n',
// title: '更新',
// mandatoryUpdateMessage: 'XXXXX',
// mandatoryContinueButtonLabel: '更新',
// },
// mandatoryInstallMode: CodePush.InstallMode.IMMEDIATE,
// 无弹窗
updateDialog: false,
installMode: CodePush.InstallMode.ON_NEXT_RESTART,
},
this.codePushStatusDidChange.bind(this),
this.codePushDownloadDidProgress.bind(this),
this.codePushOnBinaryVersionMismatch.bind(this),
);
};
codePushStatusDidChange(syncStatus) {
switch (syncStatus) {
case CodePush.SyncStatus.CHECKING_FOR_UPDATE:
this.setState({ syncMessage: '正在检查更新' });
break;
case CodePush.SyncStatus.DOWNLOADING_PACKAGE:
this.setState({ syncMessage: '正在下载更新包 ' });
break;
case CodePush.SyncStatus.AWAITING_USER_ACTION:
this.setState({ syncMessage: '等待用户动作' });
break;
case CodePush.SyncStatus.INSTALLING_UPDATE:
this.setState({ syncMessage: '正在安装更新.' });
break;
case CodePush.SyncStatus.UP_TO_DATE:
this.setState({ syncMessage: '应用已更新.', progress: false });
break;
case CodePush.SyncStatus.UPDATE_IGNORED:
this.setState({ syncMessage: '用户取消了更新.', progress: false });
break;
case CodePush.SyncStatus.UPDATE_INSTALLED:
this.setState({
syncMessage: '应用已下载,将在下次启动时应用更新',
progress: false,
});
break;
case CodePush.SyncStatus.UNKNOWN_ERROR:
this.setState({ syncMessage: '发生未知错误.', progress: false });
break;
}
}
codePushOnBinaryVersionMismatch(binary) {
console.log('handleBinaryVersionMismatchCallback');
//console.log(binary);
Alert.alert(JSON.stringify(binary) + 'native apk?');
}
codePushDownloadDidProgress(progress) {
//alert(JSON.stringify(progress)+"dowload byte")
this.setState({ progress });
//Toast.loading(`${progress.receivedBytes} of ${progress.totalBytes} bytes received`)
}
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
{this.state.syncMessage}
</Text>
<Text style={styles.welcome}>
我是要更新的文字:下午3:37
修改安装方式为下次启动安装
</Text>
</View>
);
}
}
const 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,
},
});