This repository has been archived by the owner on Mar 19, 2021. It is now read-only.
/
App.js
100 lines (86 loc) · 2.31 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
import React from 'react';
import { Font, Asset, AppLoading } from 'expo';
import { Provider } from 'react-redux';
import _ from 'lodash';
import Sentry from 'sentry-expo';
import AppNavigator from './navigation/AppNavigator';
import OnboardScreen from './screens/OnboardScreen';
import Store from './state/Store';
import fonts from './styles/fonts';
import config from './utils/config';
import DownloadManager from './utils/DownloadManager';
import Data from './data/Data';
import {
EvilIcons,
FontAwesome,
MaterialIcons,
Ionicons,
Foundation,
} from '@expo/vector-icons';
// Setup Sentry
Sentry.enableInExpoDevelopment = config.sentryEnabledInDev;
Sentry.config(config.SENTRY_PUBLIC_DSN).install();
class AppContainer extends React.Component {
state = {
appIsReady: false,
firstLoad: config.firstLoad,
};
componentWillMount() {
this._loadAssetsAsync();
}
componentWillUnmount() {
this._downloadManager && this._downloadManager.teardown();
}
_cacheFonts(fonts) {
return fonts.map(font => Font.loadAsync(font));
}
_cacheImages(images) {
return images.map(image => {
if (typeof image === 'string') {
return Image.prefetch(image);
} else {
return Asset.fromModule(image).downloadAsync();
}
});
}
async _loadAssetsAsync() {
const imageAssets = this._cacheImages([
require('./assets/videoplayer/thumb.png'),
require('./assets/videoplayer/track.png'),
]);
const fontAssets = this._cacheFonts([
fonts,
EvilIcons.font,
FontAwesome.font,
Ionicons.font,
MaterialIcons.font,
Foundation.font,
]);
try {
await Promise.all([
Store.rehydrateAsync(),
...imageAssets,
...fontAssets,
]);
Store.dispatch({ type: 'SET_DATA', data: Data });
} catch (e) {
console.log('Error downloading assets', e);
Sentry.captureException(e);
}
this._downloadManager = new DownloadManager(Store);
this.setState({ appIsReady: true });
}
render() {
if (!this.state.appIsReady) {
return <AppLoading />;
}
return this.state.firstLoad ? (
<OnboardScreen startApp={() => this.setState({ firstLoad: false })} />
) : (
<Provider store={Store}>
<AppNavigator />
</Provider>
);
}
}
export default AppContainer;