-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
115 lines (97 loc) · 3.52 KB
/
App.tsx
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
import { StoreProvider } from 'easy-peasy';
import { AppLoading } from 'expo';
import { Asset } from 'expo-asset';
import Constants from 'expo-constants';
import * as Font from 'expo-font';
import React, { SFC, useCallback, useEffect, useState } from 'react';
import { AsyncStorage } from 'react-native';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import Amplify from 'aws-amplify';
import awsconfig from './aws-exports';
Amplify.configure(awsconfig);
import * as Sentry from 'sentry-expo';
import { ApolloProvider } from '@apollo/react-hooks';
import { InitialState } from '@react-navigation/native';
import client from './ApolloClient';
import store from './models';
import Navigation from './navigation';
const NAVIGATION_STATE_KEY = `NAVIGATION_STATE_KEY-${Constants.manifest.sdkVersion}`;
const icons = [require('./assets/images/defaultUserImage.png')];
interface Props {
skipLoadingScreen?: boolean;
}
const handleResourcesAsync = async (): Promise<void[]> => {
(async (): Promise<void> => {
await Font.loadAsync({
josefinBold: require('./assets/fonts/JosefinSans-Bold.ttf'),
josefinLight: require('./assets/fonts/JosefinSans-Light.ttf'),
josefinRegular: require('./assets/fonts/JosefinSans-Regular.ttf'),
josefinSemiBold: require('./assets/fonts/JosefinSans-SemiBold.ttf'),
HelveticaNeue: require('./assets/fonts/OpenSans-Regular.ttf')
});
})();
const cacheIcons = icons.map(icon => {
return Asset.fromModule(icon).downloadAsync();
});
return Promise.all(cacheIcons);
};
// TODO: Set to false Sentry properties for prod
Sentry.init({
dsn:
'https://e8b1308767024fedb1e5c4d945326c8c@o498122.ingest.sentry.io/5576044',
enableInExpoDevelopment: true,
debug: true // Sentry will try to print out useful debugging information if something goes wrong with sending an event. Set this to `false` in production.
});
const App: SFC<Props> = ({ skipLoadingScreen }) => {
const [isNavigationReady, setIsNavigationReady] = useState(!__DEV__);
const [initialState, setInitialState] = useState<InitialState | undefined>();
const [isLoadingComplete, setIsLoadingComplete] = useState<boolean>(false);
useEffect(() => {
const restoreState = async (): Promise<void> => {
try {
const savedStateString = await AsyncStorage.getItem(
NAVIGATION_STATE_KEY
);
const state = savedStateString
? JSON.parse(savedStateString)
: undefined;
setInitialState(state);
} finally {
setIsNavigationReady(true);
}
};
if (!isNavigationReady) {
restoreState();
}
}, [isNavigationReady]);
const onStateChange = useCallback(
state => AsyncStorage.setItem(NAVIGATION_STATE_KEY, JSON.stringify(state)),
[]
);
if ((!isLoadingComplete && !skipLoadingScreen) || !isNavigationReady) {
return (
<SafeAreaProvider
initialSafeAreaInsets={{ top: 0, right: 0, bottom: 0, left: 0 }}>
<AppLoading
// @ts-ignore
startAsync={handleResourcesAsync}
onError={error => {
throw error;
}}
onFinish={() => setIsLoadingComplete(true)}
/>
</SafeAreaProvider>
);
}
return (
<ApolloProvider client={client}>
<StoreProvider store={store}>
<SafeAreaProvider
initialSafeAreaInsets={{ top: 0, right: 0, bottom: 0, left: 0 }}>
<Navigation {...{ initialState, onStateChange }} />
</SafeAreaProvider>
</StoreProvider>
</ApolloProvider>
);
};
export default App;