-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.js
More file actions
119 lines (104 loc) · 3.33 KB
/
Main.js
File metadata and controls
119 lines (104 loc) · 3.33 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
114
115
116
117
118
119
/*
* @file: Main.js
* @description: Register Application with sentry and code push.
* @date: 20.July.2018
* @author: Lancy Goyal
* */
import React, { Component } from 'react';
import CodePush from 'react-native-code-push';
// import { Sentry } from 'react-native-sentry';
import App from './src';
/**
* Configuring sentry (crash analytics)
*/
// Sentry.config("https://62ddddf6d01c4b8f963e6b33c26b415d@sentry.io/1218653").install();
/**
* Configured with a MANUAL check frequency for easy testing. For production apps, it is recommended to configure a
* different check frequency, such as ON_APP_START, for a 'hands-off' approach where CodePush.sync() does not
* need to be explicitly called. All options of CodePush.sync() are also available in this decorator.
*/
class Main extends Component {
constructor() {
super();
this.state = {
restartAllowed: false,
progress: false,
syncMessage: ''
};
}
codePushStatusDidChange(syncStatus: number) {
switch (syncStatus) {
case CodePush.SyncStatus.CHECKING_FOR_UPDATE:
this.setState({ syncMessage: 'Checking for update.' });
break;
case CodePush.SyncStatus.DOWNLOADING_PACKAGE:
this.setState({ syncMessage: 'Downloading package.' });
break;
case CodePush.SyncStatus.AWAITING_USER_ACTION:
this.setState({ syncMessage: 'Awaiting user action.' });
break;
case CodePush.SyncStatus.INSTALLING_UPDATE:
this.setState({ syncMessage: 'Installing update.' });
break;
case CodePush.SyncStatus.UP_TO_DATE:
this.setState({ syncMessage: 'App up to date.', progress: false });
break;
case CodePush.SyncStatus.UPDATE_IGNORED:
this.setState({
syncMessage: 'Update cancelled by user.',
progress: false
});
break;
case CodePush.SyncStatus.UPDATE_INSTALLED:
this.setState({
syncMessage: 'Update installed and will be applied on restart.',
progress: false
});
break;
case CodePush.SyncStatus.UNKNOWN_ERROR:
this.setState({
syncMessage: 'An unknown error occurred.',
progress: false
});
break;
}
}
codePushDownloadDidProgress(progress: boolean) {
this.setState({ progress });
}
toggleAllowRestart() {
this.state.restartAllowed ? CodePush.disallowRestart() : CodePush.allowRestart();
this.setState({ restartAllowed: !this.state.restartAllowed });
}
// Update is downloaded silently, and applied on restart (recommended)
sync() {
CodePush.sync(
{},
this.codePushStatusDidChange.bind(this),
this.codePushDownloadDidProgress.bind(this)
);
}
// Update pops a confirmation dialog, and then immediately reboots the app
syncImmediate() {
CodePush.sync(
{ installMode: CodePush.InstallMode.IMMEDIATE, updateDialog: true },
this.codePushStatusDidChange.bind(this),
this.codePushDownloadDidProgress.bind(this)
);
}
componentWillMount() {
if (process.env.NODE_ENV === 'production') {
this.syncImmediate();
} else {
this.sync();
}
}
render() {
return <App />;
}
}
const codePushOptions = {
checkFrequency: CodePush.CheckFrequency.ON_APP_START,
installMode: CodePush.InstallMode.ON_NEXT_RESUME
};
export default CodePush(codePushOptions)(Main);