-
Notifications
You must be signed in to change notification settings - Fork 9
/
App.js
105 lines (95 loc) · 3.14 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
101
102
103
104
105
import React from 'react';
import {
BackHandler,
ActivityIndicator,
StatusBar,
View,
Keyboard,
Platform,
} from 'react-native';
import { Provider } from 'react-redux';
import store from './src/redux/store';
import { connect } from 'react-redux';
import persistStore from './src/utils/persist';
import * as keyboard from './src/state/keyboard';
import Navigator, {
handleBackButton,
} from './src/containers/navigator/Navigator';
import {
Centered,
FullscreenCentered,
AppContainer,
} from './src/components/Layout';
import { Font } from 'expo';
export default class App extends React.Component {
state = {
rehydrated: false,
fontLoaded: false,
};
/**
* When show hide of react's keyboard is fired, this function is called
* it will call the redux reducer to handle state changes in the keyboard
*/
keyboardHideListener = () => {
store.dispatch(keyboard.hide());
};
/**
* When show event of react's keyboard is fired, this function is called
* it will call the redux reducer to handle state changes in the keyboard
*/
keyboardDidShowListener = () => {
store.dispatch(keyboard.show());
};
componentDidMount = async () => {
persistStore(store, () => this.setState({ rehydrated: true }));
BackHandler.addEventListener('hardwareBackPress', () =>
handleBackButton(store.getState(), store.dispatch),
);
// Load fonts and wait untill this is done before rendering
await Font.loadAsync({
'NunitoSans-Regular': require('./assets/fonts/NunitoSans/NunitoSans-Regular.ttf'),
'NunitoSans-Bold': require('./assets/fonts/NunitoSans/NunitoSans-Bold.ttf'),
'NunitoSans-LightItalic': require('./assets/fonts/NunitoSans/NunitoSans-LightItalic.ttf'),
'NunitoSans-SemiBold': require('./assets/fonts/NunitoSans/NunitoSans-SemiBold.ttf'),
'NunitoSans-ExtraBold': require('./assets/fonts/NunitoSans/NunitoSans-ExtraBold.ttf'),
'NunitoSans-Light': require('./assets/fonts/NunitoSans/NunitoSans-Light.ttf'),
Friendship_version_2: require('./assets/fonts/Friendship/Friendship.ttf'),
Futurice: require('./assets/fonts/Friendship/Friendship-Regular.ttf'),
});
this.setState({ fontLoaded: true });
this.keyboardHideListener = Keyboard.addListener(
Platform.OS === 'android' ? 'keyboardDidHide' : 'keyboardWillHide',
this.keyboardHideListener,
);
this.keyboardDidShowListener = Keyboard.addListener(
'keyboardDidShow',
this.keyboardDidShowListener,
);
};
renderActivityIndicator = () =>
this.state.rehydrated && this.state.fontLoaded ? null : (
<FullscreenCentered>
<ActivityIndicator size="large" />
</FullscreenCentered>
);
renderApp = () =>
this.state.rehydrated && this.state.fontLoaded ? (
<Provider store={store}>
<Navigator />
</Provider>
) : null;
render = () => (
<AppContainer>
{this.renderActivityIndicator()}
{this.renderApp()}
</AppContainer>
);
/**
* After unmounting the view
* we remove the keyboard listeners
*/
componentWillUnmount() {
this.keyboardHideListener.remove();
this.keyboardDidShowListener.remove();
}
}