-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
113 lines (103 loc) · 2.89 KB
/
App.tsx
File metadata and controls
113 lines (103 loc) · 2.89 KB
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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
*/
import React, {useEffect, useState} from 'react';
import {SafeAreaView, StyleSheet, Text, TouchableOpacity} from 'react-native';
import Animated from 'react-native-reanimated';
import codePush, {DownloadProgress} from 'react-native-code-push';
let codePushOptions = {checkFrequency: codePush.CheckFrequency.MANUAL};
function App(): JSX.Element {
const [syncState, setSyncState] = useState('');
const [appLabel, setAppLabel] = useState('');
const codePushStatusChange = (syncStatus: codePush.SyncStatus) => {
console.log('syncStatus=====:', syncStatus, arrSyncStatus[syncStatus]);
setSyncState(state => {
return state + arrSyncStatus[syncStatus] + ' | ';
});
};
const codePushDownloadProgress = (progress: DownloadProgress) => {
console.log('progress=====:', progress);
};
const onButtonPress = () => {
setSyncState('');
// codePush.restartApp();
// return;
codePush.sync(
{
updateDialog: true,
installMode: codePush.InstallMode.IMMEDIATE,
},
codePushStatusChange,
codePushDownloadProgress,
);
};
useEffect(() => {
codePush
.getUpdateMetadata(codePush.UpdateState.RUNNING)
.then((metadata: any) => {
console.log('🚀====== ~ .then ~ metadata:', metadata);
if (metadata) {
const label = metadata.label;
setAppLabel(label);
}
});
}, []);
return (
<SafeAreaView style={styles.safeArea}>
<Animated.View style={styles.content}>
<Text style={styles.title}>Code-push Testing</Text>
{/* <Text style={styles.text}>Press R to crash on reload</Text> */}
<Text style={styles.text}>Test code push test </Text>
<Text style={styles.text}>Code-push label: {appLabel}</Text>
<TouchableOpacity onPress={onButtonPress}>
<Text style={{padding: 14, fontSize: 20, color: 'red'}}>
Press to Check for Updates:{syncState}
</Text>
</TouchableOpacity>
</Animated.View>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
safeArea: {
flex: 1,
},
content: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
title: {
fontSize: 24,
fontWeight: '600',
paddingBottom: 30,
},
text: {
paddingVertical: 10,
fontSize: 20,
},
});
const MyApp = codePush(codePushOptions)(App);
export default MyApp;
const arrSyncStatus = [
'UP_TO_DATE',
'UPDATE_INSTALLED',
'UPDATE_IGNORED',
'UNKNOWN_ERROR',
'SYNC_IN_PROGRESS',
'CHECKING_FOR_UPDATE',
'AWAITING_USER_ACTION',
'DOWNLOADING_PACKAGE',
'INSTALLING_UPDATE',
];
/**
* e2e codePushStatusChange for an code-push.
* 5, 'CHECKING_FOR_UPDATE'
* 6, 'AWAITING_USER_ACTION': await to click "continue" button in the dialog
* 7, 'DOWNLOADING_PACKAGE'
* 8, 'INSTALLING_UPDATE'
* 1, 'UPDATE_INSTALLED'
*/