generated from Dey-Sumit/expo-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
61 lines (51 loc) · 1.92 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
import * as SplashScreen from "expo-splash-screen";
import { useCallback, useEffect, useState } from "react";
import { config } from "@gluestack-ui/config";
import { GluestackUIProvider } from "@gluestack-ui/themed";
import { NavigationContainer } from "@react-navigation/native";
import { useAuth } from "~/hooks/auth.hook";
import AuthStackScreens from "./src/navigators/AuthStack.navigator";
import MainStackScreens from "./src/navigators/MainStack.navigator";
// Keep the splash screen visible while we fetch resources
SplashScreen.preventAutoHideAsync();
//
const App = () => {
const [appIsReady, setAppIsReady] = useState(false);
const { isAuthenticated } = useAuth();
useEffect(() => {
async function prepare() {
try {
// Pre-load fonts, make any API calls you need to do here
// Artificially delay for two seconds to simulate a slow loading
// experience. Please remove this if you copy and paste the code!
await new Promise((resolve) => setTimeout(resolve, 1000));
} catch (e) {
console.warn(e);
} finally {
// Tell the application to render
setAppIsReady(true);
}
}
prepare();
}, []);
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 Navigation container is ready
await SplashScreen.hideAsync();
}
}, [appIsReady]);
if (!appIsReady) {
return null;
}
return (
<GluestackUIProvider config={config}>
<NavigationContainer onReady={onLayoutRootView}>
{!isAuthenticated ? <AuthStackScreens /> : <MainStackScreens />}
</NavigationContainer>
</GluestackUIProvider>
);
};
export default App;