-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ios.js
82 lines (70 loc) · 2.08 KB
/
index.ios.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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*/
'use strict';
const React = require("react-native");
const LoginComponent = require("./components/LoginComponent");
const RootTab = require("./components/RootTab");
const CommonComponents = require("./common/CommonComponents");
const OSCService = require("./service/OSCService");
const ShakeComponent = require('./components/ShakeComponent');
const codePush = require('react-native-code-push');
const constant = require('./config').constant;
const Toast = require('@remobile/react-native-toast');
const {
AppRegistry,
} = React;
const OSCGit = React.createClass({
getInitialState() {
return {loading: true}
},
getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
},
_query() {
OSCService.getUserFromCache()
.then(() => {
this.setState({loading: false});
});
},
componentWillMount() {
this._query();
OSCService.addListener('didLogout', () => {
Toast.showLongBottom("用户登出.");
this.setState(this.getInitialState());
this._query();
});
const random = this.getRandomInt(1, 10);
const cpKey = random % 2 == 0 ? constant.code_push.STAGING_KEY : constant.code_push.PRODUCTION_KEY;
// Prompt the user when an update is available
// and then display a "downloading" modal
//, (status) => {
// switch (status) {
// case codePush.SyncStatus.DOWNLOADING_PACKAGE:
// // Show "downloading" modal
// break;
// case codePush.SyncStatus.INSTALLING_UPDATE:
// // Hide "downloading" modal
// break;
// }
//}
codePush.sync({
updateDialog: true,
installMode: codePush.InstallMode.IMMEDIATE,
deploymentKey:cpKey
});
},
componentDidMount() {
},
componentWillUnmount: function() {
OSCService.removeListener('didLogout');
},
render() {
if(this.state.loading) {
return CommonComponents.renderLoadingView();
}
return <RootTab />;
}
});
AppRegistry.registerComponent('OSCGit', () => OSCGit);