-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathApp.tsx
86 lines (79 loc) · 3.13 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
import * as Font from "expo-font";
import store from "./src/modules/common/redux/store";
import { Provider } from "react-redux";
import "react-native-url-polyfill/auto";
import { persistStore } from "redux-persist";
import * as SplashScreen from "expo-splash-screen";
import { checkIfFirstLaunch } from "./src/modules/common/utils/storage";
import { PersistGate } from "redux-persist/integration/react";
import { NavigationContainer } from "@react-navigation/native";
import React, { useState, useEffect, useCallback } from "react";
import { SafeAreaProvider } from "react-native-safe-area-context";
import GeneralContextProvider from "./src/modules/common/context/GeneralContext";
import RootStackNavigator from "@modules/common/navigators/RootStackNavigator";
import * as serviceWorkerRegistration from "./src/serviceWorkerRegistration";
import {
Lexend_400Regular,
Lexend_500Medium,
Lexend_600SemiBold,
Lexend_700Bold,
} from "@expo-google-fonts/lexend";
SplashScreen.preventAutoHideAsync();
const persistor = persistStore(store);
export default function App(): React.ReactElement | null {
const [isCalendarModalOpen, setIsCalendarModalOpen] = useState(false);
const [isCampusSelectModalOpen, setIsCampusSelectModalOpen] = useState(false);
const [isShareModalOpen, setIsShareModalOpen] = useState(false);
const [appIsReady, setAppIsReady] = useState(false);
const [isFirstLaunch, setIsFirstLaunch] = useState(false);
useEffect(() => {
Promise.all([
Font.loadAsync({
IcoMoon: require("./assets/icomoon/fonts/icomoon.ttf"),
Lexend_400Regular,
Lexend_500Medium,
Lexend_700Bold,
Lexend_600SemiBold,
}),
checkIfFirstLaunch(),
])
.then((values) => {
setIsFirstLaunch(values[1]);
})
.finally(() => {
setAppIsReady(true);
});
}, []);
const onLayoutRootView = useCallback(async () => {
if (appIsReady) {
await SplashScreen.hideAsync();
}
}, [appIsReady]);
if (!appIsReady) {
return null;
}
return (
<SafeAreaProvider onLayout={onLayoutRootView}>
<NavigationContainer>
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<GeneralContextProvider
value={{
isCalendarModalOpen,
setIsCalendarModalOpen,
isCampusSelectModalOpen,
setIsCampusSelectModalOpen,
isShareModalOpen,
setIsShareModalOpen,
isFirstLaunch,
}}
>
<RootStackNavigator />
</GeneralContextProvider>
</PersistGate>
</Provider>
</NavigationContainer>
</SafeAreaProvider>
);
}
serviceWorkerRegistration.register();