-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathApp.js
163 lines (140 loc) · 5.22 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import React from 'react';
import {StatusBar, StyleSheet, View} from 'react-native';
import {setCustomText} from 'react-native-global-props';
import {AppLoading, Asset, Font, Icon, SplashScreen, registerRootComponent} from 'expo';
import Colors from './constants/Colors';
import AppNavigator from './navigation/AppNavigator';
import {Provider} from 'react-redux';
import {PersistGate} from 'redux-persist/integration/react';
import {persistor, store} from './store';
import AlertProvider from './components/alert/alert.component';
import PlayerComponent from './components/Player';
import NavigationService from './services/NavigationService';
import {fetchReleases, validateAccessToken, fetchArtistOfTheWeek, getProfile} from './actions';
import {API_ENDPOINT, DEV} from 'react-native-dotenv';
import playerService from './playerService';
import TrackPlayer from 'react-native-track-player';
console.log('server endpoint: ' + API_ENDPOINT);
if (!!+DEV) {
store.subscribe(() => console.log('store', store.getState()));
}
// Setting default styles for all Text components.
const customTextProps = {
style: {
fontFamily: 'robotoRegular',
color: Colors.fontColor,
},
};
// persistor.purge();
// gets the current screen from navigation state
function getActiveRouteName(navigationState) {
if (!navigationState) {
return null;
}
const route = navigationState.routes[navigationState.index];
// dive into nested navigators
if (route.routes) {
return getActiveRouteName(route);
}
return route.routeName;
}
export default class App extends React.Component {
state = {
isLoadingComplete: false,
currentScreen: 'Home',
};
constructor(props) {
super(props);
SplashScreen.preventAutoHide();
}
componentDidMount() {
}
componentWillUnmount() {
}
render() {
return (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
{!this.state.isLoadingComplete && !this.props.skipLoadingScreen ?
<AppLoading
startAsync={this._loadResourcesAsync}
onError={this._handleLoadingError}
onFinish={this._handleFinishLoading}
/>
:
<AlertProvider>
<View style={styles.songInfoContainer}>
<StatusBar barStyle="light-content"/>
<AppNavigator
style={{backgroundColor: Colors.backgroundColor}}
ref={navigatorRef => {
NavigationService.setTopLevelNavigator(navigatorRef);
}}
onNavigationStateChange={(prevState, currentState) => {
const currentScreen = getActiveRouteName(currentState);
const prevScreen = getActiveRouteName(prevState);
//reload the profile for these specific screens
if (prevScreen !== currentScreen) {
if (currentScreen === 'Profile' || currentScreen === 'Wallet' || currentScreen === 'Invite') {
if (store.getState().auth.loggedIn) {
store.dispatch(getProfile());
}
}
// the line below uses the Google Analytics tracker
// change the tracker here to use other Mobile analytics SDK.
this.setState({currentScreen});
}
}}/>
<PlayerComponent currentScreen={this.state.currentScreen}/>
</View>
</AlertProvider>
}
</PersistGate>
</Provider>
);
}
_loadResourcesAsync = async () => {
return Promise.all([
Asset.loadAsync([
require('./assets/icons/clap-grey.png'),
require('./assets/icons/clap-white.png'),
require('./assets/icons/library-grey.png'),
require('./assets/icons/library-white.png'),
require('./assets/images/logo.png'),
require('./assets/images/invite.png'),
require('./assets/images/guitar.png'),
]),
Font.loadAsync({
...Icon.Ionicons.font,
'robotoRegular': require('./assets/fonts/Roboto-Regular.ttf'),
'robotoMedium': require('./assets/fonts/Roboto-Medium.ttf'),
'robotoBold': require('./assets/fonts/Roboto-Bold.ttf'),
}),
store.dispatch(validateAccessToken()).then(() => {
return Promise.all([
store.dispatch(fetchArtistOfTheWeek()),
store.dispatch(fetchReleases())]);
}),
]);
};
setComponentDefaults() {
setCustomText(customTextProps);
}
_handleLoadingError = error => {
// In this case, you might want to report the error to your error
// reporting service, for example Sentry
console.warn(error);
};
_handleFinishLoading = () => {
this.setComponentDefaults();
this.setState({isLoadingComplete: true});
TrackPlayer.registerPlaybackService(() => playerService);
SplashScreen.hide();
};
}
const styles = StyleSheet.create({
songInfoContainer: {
flex: 1,
backgroundColor: Colors.backgroundColor,
},
});