-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
75 lines (64 loc) · 2.02 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
import 'react-native-gesture-handler'
import { SplashScreen as SplashScreenComponent } from '@components/SplashScreen'
import { CartContextProvider } from '@contexts/CartContext'
import { SearchContextProvider } from '@contexts/SearchContext'
import { Baloo2_700Bold } from '@expo-google-fonts/baloo-2'
import { Roboto_400Regular, Roboto_700Bold } from '@expo-google-fonts/roboto'
import { Routes } from '@routes/index'
import { THEME } from '@styles/theme'
import { useFonts } from 'expo-font'
import * as SplashScreen from 'expo-splash-screen'
import { useEffect, useState } from 'react'
import { StatusBar } from 'react-native'
import { View } from 'react-native'
import { GestureHandlerRootView } from 'react-native-gesture-handler'
SplashScreen.preventAutoHideAsync()
export default function App() {
const [showSplashScreen, setShowSplashScreen] = useState(true)
const [showContent, setShowContent] = useState(false)
const [isFontLoaded, hasFontError] = useFonts({
Roboto_400Regular,
Roboto_700Bold,
Baloo2_700Bold,
})
useEffect(() => {
if (isFontLoaded || hasFontError) {
SplashScreen.hideAsync()
}
}, [hasFontError, isFontLoaded])
useEffect(() => {
const timerSC = setTimeout(() => {
setShowSplashScreen(false)
}, 3000)
const timerContent = setTimeout(() => {
setShowContent(true)
}, 2000)
return () => {
clearTimeout(timerSC)
clearTimeout(timerContent)
}
}, [])
if (!isFontLoaded && !hasFontError) {
return (
<View
style={{
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: THEME.COLORS.purpleDark,
}}
/>
)
}
return (
<GestureHandlerRootView style={{ flex: 1 }}>
<StatusBar translucent />
<CartContextProvider>
<SearchContextProvider>
{showContent && <Routes />}
{showSplashScreen && <SplashScreenComponent />}
</SearchContextProvider>
</CartContextProvider>
</GestureHandlerRootView>
)
}