-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.js
More file actions
63 lines (55 loc) · 1.94 KB
/
App.js
File metadata and controls
63 lines (55 loc) · 1.94 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
61
62
63
import React, { useState, useEffect } from "react";
import { View } from "react-native";
import * as SplashScreen from "expo-splash-screen";
import AppNavigator from "./src/navigation/AppNavigator";
import CustomSplashScreen from "./src/screens/onboarding/SplashScreen";
import { UserProvider } from "./src/context/UserContext";
import { AuthProvider } from "./src/context/AuthContext";
import { CartProvider } from "./src/context/CartContext";
// Keep the native splash screen visible while we fetch resources or do setup
SplashScreen.preventAutoHideAsync();
export default function App() {
const [appIsReady, setAppIsReady] = useState(false);
const [showCustomSplash, setShowCustomSplash] = useState(true);
useEffect(() => {
async function prepare() {
try {
// Pre-load fonts, make any API calls you need to do here
await new Promise((resolve) => setTimeout(resolve, 2000));
} catch (e) {
console.warn(e);
} finally {
// Tell the application to render
setAppIsReady(true);
}
}
prepare();
}, []);
const onLayoutRootView = 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 rendering its initial state and rendering its first view. From this moment onwards, the native splash screen is gone.
// But we still want to show OUR custom splash screen.
// So we hidenative splash here.
await SplashScreen.hideAsync();
}
};
if (!appIsReady) {
return null;
}
if (showCustomSplash) {
return (
<View style={{ flex: 1 }} onLayout={onLayoutRootView}>
<CustomSplashScreen onFinish={() => setShowCustomSplash(false)} />
</View>
);
}
return (
<AuthProvider>
<UserProvider>
<CartProvider>
<AppNavigator />
</CartProvider>
</UserProvider>
</AuthProvider>
);
}