-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathApp.js
More file actions
67 lines (61 loc) · 1.75 KB
/
Copy pathApp.js
File metadata and controls
67 lines (61 loc) · 1.75 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
import React, {PureComponent} from 'react';
import {StatusBar, View} from 'react-native';
import {Provider} from 'react-redux';
import SplashScreen from 'react-native-splash-screen';
import {pickBy, identity} from 'lodash';
import AppNavigator from './src';
import {setAxios} from './src/service/setAxios';
import store from './src/store';
import AuthUtil from './src/utils/AuthUtil';
import {switchAPPLanguage, toInitialAuthInfo} from './src/actions';
import Toast from './src/utils/Toast';
class App extends PureComponent {
constructor(props) {
super(props);
this.state = {};
this.initialInfo = this.initialInfo.bind(this);
}
static async getDerivedStateFromProps() {
const language = await AuthUtil.getAppLanguage();
if (language) {
await switchAPPLanguage(language); // 设置app语言环境
} else {
await switchAPPLanguage('zhHans'); // 默认中文
}
}
componentDidMount() {
SplashScreen.hide();
setAxios(); // 网络设置
global.toast = this.refs.toast; // 全局引用赋值
this.initialInfo();
}
async initialInfo() {
const userInfo = await AuthUtil.getUserInfo();
const themeColor = await AuthUtil.getThemeColor();
const authInfo = pickBy(
{
isLogin: !!userInfo,
userInfo,
themeColor,
},
identity,
);
if (Object.keys(authInfo).length === 0) {
return;
}
console.log('初始化缓存信息', authInfo);
toInitialAuthInfo(authInfo);
}
render() {
return (
<Provider store={store}>
<View style={{flex: 1}}>
<StatusBar barStyle={'light-content'} translucent={true} />
<AppNavigator />
<Toast ref="toast" />
</View>
</Provider>
);
}
}
export default App;