-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
100 lines (88 loc) · 2.84 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
import * as React from "react";
import "react-native-reanimated";
import { NavigationContainer } from "@react-navigation/native";
import { QueryClient, QueryClientProvider } from "react-query";
import { SingletonHooksContainer } from "react-singleton-hook";
import { StatusBar } from "expo-status-bar";
import { Asset } from "expo-asset";
import * as Font from "expo-font";
import AppLoading from "expo-app-loading";
import {
FontAwesome,
FontAwesome5,
Ionicons,
MaterialCommunityIcons,
MaterialIcons,
} from "@expo/vector-icons";
import { BottomSheetModalProvider } from "@gorhom/bottom-sheet";
import AuthedNavigator from "./src/navigation/authed";
import UnauthedNavigator from "./src/navigation/unauthed";
import { useAuth } from "./src/utils/auth";
const queryClient = new QueryClient({
defaultOptions: {
queries: {
keepPreviousData: true,
refetchOnWindowFocus: false,
},
},
});
const cacheImages = (images) =>
images.map((image) => Asset.fromModule(image).downloadAsync());
const cacheFonts = (fonts) => fonts.map((font) => Font.loadAsync(font));
const loadAssetsAsync = async () => {
const imageAssets = cacheImages([
require("./assets/icons/american.png"),
require("./assets/icons/asian.png"),
require("./assets/icons/healthy.png"),
require("./assets/icons/indian.png"),
require("./assets/icons/italian.png"),
require("./assets/icons/lebanese.png"),
require("./assets/icons/mexican.png"),
require("./assets/icons/sandwiches.png"),
require("./assets/icons/vegan.png"),
require("./assets/icons/camera-white.png"),
require("./assets/icons/camera-white-no-bg.png"),
require("./assets/icons/sombrero.png"),
require("./assets/icons/pin.png"),
require("./assets/icons/vigilante.png"),
require("./assets/icons/hexagon.png"),
require("./assets/icons/leafs.png"),
require("./assets/icons/mountain.png"),
]);
const fontAssets = cacheFonts([
FontAwesome.font,
FontAwesome5.font,
Ionicons.font,
MaterialIcons.font,
MaterialCommunityIcons.font,
]);
await Promise.all([...imageAssets, ...fontAssets]);
};
const Navigation: React.FC = () => {
const { isInitializing, isLoggedIn } = useAuth();
const [isLoading, setIsLoading] = React.useState<boolean>(true);
if (isInitializing || isLoading) {
return (
<AppLoading
startAsync={loadAssetsAsync}
onFinish={() => setIsLoading(false)}
onError={console.warn}
/>
);
}
return (
<NavigationContainer>
<BottomSheetModalProvider>
{isLoggedIn ? <AuthedNavigator /> : <UnauthedNavigator />}
</BottomSheetModalProvider>
</NavigationContainer>
);
};
const App: React.FC = () => (
<QueryClientProvider client={queryClient}>
<SingletonHooksContainer />
<StatusBar style="dark" />
<Navigation />
</QueryClientProvider>
);
export default App;