-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
82 lines (70 loc) · 2.46 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
import "react-native-gesture-handler";
import "react-native-url-polyfill/auto";
import { useCallback, useEffect, useState } from "react";
import { useFonts } from "expo-font";
import * as SplashScreen from "expo-splash-screen";
import firestore from "@react-native-firebase/firestore";
import auth from "@react-native-firebase/auth";
import { RecoilRoot } from "recoil";
import RecoilNexus from "recoil-nexus";
import { BaseNavigator } from "@navigators/BaseNavigator";
import { ThemeProvider } from "@contexts/theme";
import { AuthProvider } from "@contexts/auth";
import { ENVIRONMENT } from "@env";
import "expo-dev-client"; // Improve debugging when using dev-client
// Keep the splash screen visible fetching resources
SplashScreen.preventAutoHideAsync();
const App = () => {
// Load fonts
const [fontsLoaded] = useFonts({
WorkSans: require("@assets/fonts/WorkSans-Regular.ttf"),
WorkSansBold: require("@assets/fonts/WorkSans-Bold.ttf"),
antoutline: require("@ant-design/icons-react-native/fonts/antoutline.ttf"),
antfill: require("@ant-design/icons-react-native/fonts/antfill.ttf"),
});
// Set an initializing state whilst Firebase connects
const [isFirebaseInit, setIsFirebaseInit] = useState(true);
useEffect(() => {
if (ENVIRONMENT === "dev") {
firestore().useEmulator("localhost", 8080);
auth().useEmulator("http://localhost:9099");
}
}, []);
// Memoized function to remove splash screen
/**
* Must be loaded/completed before splash screen is removed:
* - Fonts loaded
* - Firebase connection finished initializing
*/
const onRootLayoutView = useCallback(async () => {
if (fontsLoaded && !isFirebaseInit) {
await SplashScreen.hideAsync();
}
}, [fontsLoaded, isFirebaseInit]);
// Call the onRootLayoutView function to remove splash screen
// This setup prevents it from being called multiple times
useEffect(() => {
onRootLayoutView();
}, [onRootLayoutView]);
// Set IS_READY to true to allow the background tracking task to update the geolocation state without breaking
useEffect(() => {
process.env.IS_READY = "true";
}, []);
if (!fontsLoaded) {
return null;
}
return (
<AuthProvider
setFirebaseInitializing={setIsFirebaseInit}
isFirebaseInitializing={isFirebaseInit}
>
<ThemeProvider>
<RecoilRoot>
<RecoilNexus />
<BaseNavigator />
</RecoilRoot>
</ThemeProvider>
</AuthProvider>
);
};
export default App;