-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
71 lines (55 loc) · 1.87 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
import React, { Component } from 'react';
import { StyleSheet, View } from 'react-native';
import { createStore } from 'redux';
import { Provider } from 'react-redux';
import reducer from './reducers';
import middleware from './middleware';
import { receiveDecks } from './actions/index';
import * as Font from 'expo-font';
import { robotoMedium, robotoRegular } from './utils/fonts';
import NavigationService from './navigation/navigationService';
import { fetchAllDecks } from './utils/api';
import { setLocalNotification } from './utils/notificationHelper';
import StackNavigation from './navigation/StackNavigation';
export default class App extends Component {
store = createStore(reducer, middleware);
state = {
prerequisitesLoaded: false // Flags if the Roboto fonts and data have been loaded
};
async componentDidMount() {
await setLocalNotification();
const loadDecksPromise = fetchAllDecks();
const loadFontsPromise = Font.loadAsync({
[robotoRegular]: require('./assets/fonts/Roboto-Regular.ttf'),
[robotoMedium]: require('./assets/fonts/Roboto-Medium.ttf')
});
Promise.all([loadDecksPromise, loadFontsPromise])
.then(values => {
const decks = values[0];
this.store.dispatch(receiveDecks(decks));
this.setState({
prerequisitesLoaded: true
});
});
}
// --------------------------------------------------------------------------------
render() {
return (
<Provider store={this.store}>
<View style={styles.appContainer}>
{this.state.prerequisitesLoaded && (
<StackNavigation ref={navigatorRef => {
NavigationService.setTopLevelNavigator(navigatorRef);
}} />
)}
</View>
</Provider>
);
}
}
const styles = StyleSheet.create({
appContainer: {
flex: 1,
backgroundColor: '#fff'
}
});