-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
74 lines (64 loc) · 1.74 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
import React, {Component} from 'react';
import {View} from 'react-native';
import {AppLoading} from 'expo';
import * as SecureStore from 'expo-secure-store';
import GraphQLProvider from './src/Apollo';
import {TOKEN_KEY} from './src/Consts/vars';
import {ErrorReporting, Analytics} from './src/Services';
import {
NetworkStatus,
BlockingUpdateManager,
UpdateManager
} from './src/Components';
import LoggedIn from './src/LoggedIn';
import {Login} from './src/Views';
class App extends Component {
constructor(props) {
super(props);
this.state = {
splashScreen: true,
token: null
};
}
componentDidMount() {
this.initializeApp();
}
initializeApp = async () => {
ErrorReporting.init();
Analytics.init();
let token;
try {
token = await SecureStore.getItemAsync(TOKEN_KEY);
} catch (e) {
SecureStore.deleteItemAsync(TOKEN_KEY);
ErrorReporting.captureException(e);
}
if (token) this.setState({token: token || null, loggedIn: true});
this.setState({splashScreen: false});
};
render() {
const authenticated = this.state.token ? true : false;
if (this.state.splashScreen) return <AppLoading />;
if (authenticated) {
return (
<NetworkStatus>
<GraphQLProvider token={this.state.token}>
<UpdateManager>
<LoggedIn initializeApp={this.initializeApp} />
</UpdateManager>
</GraphQLProvider>
</NetworkStatus>
);
}
return (
<NetworkStatus>
<GraphQLProvider>
<BlockingUpdateManager>
<Login initializeApp={this.initializeApp} />
</BlockingUpdateManager>
</GraphQLProvider>
</NetworkStatus>
);
}
}
export default App;