-
Notifications
You must be signed in to change notification settings - Fork 6
/
App.tsx
81 lines (67 loc) · 2.51 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
import {
ApolloClient,
ApolloProvider,
NormalizedCacheObject,
} from "@apollo/client";
import { ActionSheetProvider } from "@expo/react-native-action-sheet";
import * as Sentry from "@sentry/react-native";
import * as SplashScreen from "expo-splash-screen";
import React, { useCallback, useEffect } from "react";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import { RootSiblingParent } from "react-native-root-siblings";
import { enableScreens } from "react-native-screens";
import { createClient } from "yep/graphql/client";
import { Navigation } from "yep/navigation";
import { useManrope } from "yep/typefaces";
import { AccessTokenProvider, useAccessToken } from "./useAccessToken";
enableScreens();
Sentry.init({
dsn: "https://[email protected]/5248224",
debug: __DEV__, // If `true`, Sentry will try to print out useful debugging information if something goes wrong with sending the event. Set it to `false` in production
});
SplashScreen.preventAutoHideAsync();
// TODO: implement better error handling + user-facing notifications
export default function App() {
return (
<RootSiblingParent>
<AccessTokenProvider>
<InnerApp />
</AccessTokenProvider>
</RootSiblingParent>
);
}
function InnerApp() {
const { checkedForToken, accessToken } = useAccessToken();
const fontsLoaded = useManrope();
const [client, setClient] =
React.useState<ApolloClient<NormalizedCacheObject> | null>(null);
useEffect(function createClientWithPersistedCache() {
(async () => {
const client = await createClient();
setClient(client);
})();
}, []);
const appIsReady = fontsLoaded && checkedForToken && !!client;
const onLayoutRootView = useCallback(async () => {
if (appIsReady) {
// This tells the splash screen to hide immediately! If we call this after
// `setAppIsReady`, then we may see a blank screen while the app is
// loading its initial state and rendering its first pixels. So instead,
// we hide the splash screen once we know the root view has already
// performed layout.
await SplashScreen.hideAsync();
}
}, [appIsReady]);
if (!appIsReady) {
return null;
}
return (
<GestureHandlerRootView style={{ flex: 1 }} onLayout={onLayoutRootView}>
<ApolloProvider client={client}>
<ActionSheetProvider>
<Navigation accessToken={accessToken} />
</ActionSheetProvider>
</ApolloProvider>
</GestureHandlerRootView>
);
}