-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
60 lines (52 loc) · 1.61 KB
/
App.tsx
File metadata and controls
60 lines (52 loc) · 1.61 KB
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
import Root from "./src/navigation/Root";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { useCallback, useEffect, useState } from "react";
import { SafeAreaProvider } from "react-native-safe-area-context";
import { FocusContext, InsetsContext } from "./src/utils/context";
import * as SplashScreen from "expo-splash-screen";
import { Insets } from "./src/utils";
SplashScreen.preventAutoHideAsync();
const queryClient = new QueryClient();
async function enableMocking() {
if (!__DEV__) {
return;
}
await import("./msw.polyfills");
const { server } = await import("./src/mocks/server");
server.listen({ onUnhandledRequest: "bypass" });
}
export default function App() {
const [appIsReady, setAppIsReady] = useState(false);
const [insets, setInsets] = useState<Insets>({
top: 0,
bottom: 0,
left: 0,
right: 0,
});
useEffect(() => {
async function prepare() {
setAppIsReady(true);
}
prepare();
enableMocking().then(() => console.log("mocking server on"));
}, []);
const onLayoutRootView = useCallback(async () => {
if (appIsReady) {
await SplashScreen.hideAsync();
}
}, [appIsReady]);
if (!appIsReady) {
return null;
}
return (
<InsetsContext.Provider value={{ insets, setInsets }}>
<FocusContext.Provider value={{ id: "", setId: () => {} }}>
<QueryClientProvider client={queryClient}>
<SafeAreaProvider onLayout={onLayoutRootView}>
<Root></Root>
</SafeAreaProvider>
</QueryClientProvider>
</FocusContext.Provider>
</InsetsContext.Provider>
);
}