-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
65 lines (54 loc) · 1.66 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
import React from 'react';
import { UIManager, AsyncStorage } from 'react-native';
import { ThemeProvider } from 'styled-components';
import { AppLoading } from 'expo';
import { ApolloProvider } from 'react-apollo';
import { ActionSheetProvider } from '@expo/react-native-action-sheet';
import { colors, fonts, images } from './src/utils/constants';
import { cacheFonts, cacheImages } from './src/utils/caches';
import { store, client } from './src/store';
import { login } from './src/actions/user';
import AppNavigator from './src/navigations';
if (UIManager.setLayoutAnimationEnabledExperimental) {
UIManager.setLayoutAnimationEnabledExperimental(true);
}
export default class App extends React.Component {
state = {
appIsReady: false,
};
async componentWillMount() {
// AsyncStorage.removeItem('@ipeedy');
await this._checkIfToken();
await this._loadAssetsAsync();
}
_checkIfToken = async () => {
try {
const token = await AsyncStorage.getItem('@ipeedy');
if (token != null) {
store.dispatch(login());
}
} catch (error) {
throw error;
}
};
async _loadAssetsAsync() {
const fontAssets = cacheFonts(fonts);
const imageAssets = cacheImages(images);
await Promise.all([...fontAssets, ...imageAssets]);
this.setState({ appIsReady: true });
}
render() {
if (this.state.appIsReady) {
return (
<ApolloProvider client={client} store={store}>
<ActionSheetProvider>
<ThemeProvider theme={colors}>
<AppNavigator />
</ThemeProvider>
</ActionSheetProvider>
</ApolloProvider>
);
}
return <AppLoading />;
}
}