-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
49 lines (39 loc) · 1.23 KB
/
main.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
import Expo from 'expo';
import React from 'react';
import {AsyncStorage} from 'react-native';
import {Provider} from 'react-redux';
import {compose, applyMiddleware, createStore} from 'redux';
import {persistStore, autoRehydrate} from 'redux-persist';
import thunk from 'redux-thunk';
import reducer from './src/reducers';
import App from './src/App';
const store = createStore(reducer, undefined, compose(applyMiddleware(thunk), autoRehydrate()));
class FloodIt extends React.Component {
async componentWillMount() {
await this._loadAssetsAsync();
await this._persistStore();
this.setState({appIsReady: true});
}
async _loadAssetsAsync() {
const localImages = [
require('./assets/icons/app.png'),
require('./assets/icons/new-game.png')
].map(image => Expo.Asset.fromModule(image).downloadAsync());
return await Promise.all([...localImages]);
}
async _persistStore() {
return new Promise(resolve => persistStore(store, {storage: AsyncStorage}, resolve));
}
state = {
appIsReady: false
};
render() {
if (!this.state.appIsReady) return <Expo.AppLoading/>;
return (
<Provider store={store}>
<App/>
</Provider>
);
}
}
Expo.registerRootComponent(FloodIt);