forked from gitpoint/git-point
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
133 lines (111 loc) · 2.86 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
124
125
126
127
128
129
130
131
132
133
import React, { Component } from 'react';
import { Provider } from 'react-redux';
import styled from 'styled-components/native';
import {
AppRegistry,
AsyncStorage,
LayoutAnimation,
StatusBar,
Platform,
} from 'react-native';
import { persistStore } from 'redux-persist';
import createEncryptor from 'redux-persist-transform-encrypt';
import DeviceInfo from 'react-native-device-info';
import md5 from 'md5';
import codePush from 'react-native-code-push';
import { colors, getStatusBarConfig } from 'config';
import { getCurrentLocale, configureLocale } from 'utils';
import { GitPoint } from './routes';
import { configureStore } from './root.store';
const Container = styled.View`
align-items: center;
background-color: ${colors.white}
flex: 1;
justify-content: center;
`;
const Logo = styled.Image`
height: 100;
width: 100;
`;
if (console) {
console.disableYellowBox = true; // eslint-disable-line no-console
}
class App extends Component {
static async initLocale() {
const locale = await getCurrentLocale();
configureLocale(locale);
}
constructor() {
super();
this.state = {
rehydrated: false,
};
this.statusBarHandler = this.statusBarHandler.bind(this);
}
componentWillMount() {
const encryptor = createEncryptor({
secretKey: md5(DeviceInfo.getUniqueID()),
});
persistStore(
configureStore,
{
storage: AsyncStorage,
transforms: [encryptor],
whitelist: ['auth'],
},
() => {
this.setState({ rehydrated: true });
}
);
this.constructor.initLocale();
}
componentDidMount() {
if (!__DEV__) {
codePush.sync({
updateDialog: false,
installMode: codePush.InstallMode.IMMEDIATE,
});
}
}
componentWillUpdate() {
LayoutAnimation.spring();
}
getCurrentRouteName(navigationState) {
if (!navigationState) {
return null;
}
const route = navigationState.routes[navigationState.index];
if (route.routes) {
return this.getCurrentRouteName(route);
}
return route.routeName;
}
statusBarHandler(prev, next) {
const routeName = this.getCurrentRouteName(next);
const { translucent, backgroundColor, barStyle } = getStatusBarConfig(
routeName
);
if (Platform.OS === 'android') {
StatusBar.setTranslucent(translucent);
StatusBar.setBackgroundColor(backgroundColor);
}
StatusBar.setBarStyle(barStyle);
}
render() {
if (!this.state.rehydrated) {
return (
<Container>
<Logo source={require('./src/assets/logo-black.png')} />
</Container>
);
}
return (
<Provider store={configureStore}>
<GitPoint onNavigationStateChange={this.statusBarHandler}>
<StatusBar />
</GitPoint>
</Provider>
);
}
}
AppRegistry.registerComponent('GitPoint', () => App);