-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
119 lines (107 loc) · 2.71 KB
/
App.js
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import { AppLoading, SplashScreen, Updates } from 'expo'
import { Asset } from 'expo-asset'
import Constants from 'expo-constants'
import React from 'react'
import { Animated, StyleSheet, View } from 'react-native'
import { Provider } from 'react-redux'
import { createStore } from 'redux'
import Main from './components/Main'
import reducer from './reducers'
import middleware from './middleware'
const store = createStore(reducer, middleware)
// Instruct SplashScreen not to hide yet, we want to do this manually
SplashScreen.preventAutoHide()
export default function App() {
return (
<AnimatedAppLoader image={{ uri: Constants.manifest.splash.image }}>
<Provider store={store}>
<Main />
</Provider>
</AnimatedAppLoader>
)
}
function AnimatedAppLoader({ children, image }) {
const [isSplashReady, setSplashReady] = React.useState(false)
const startAsync = React.useMemo(
// If you use a local image with require(...), use `Asset.fromModule`
() => () => Asset.fromURI(image).downloadAsync(),
[image]
)
const onFinish = React.useMemo(() => setSplashReady(true), [])
if (!isSplashReady) {
return (
<AppLoading
startAsync={startAsync}
onError={console.error}
onFinish={onFinish}
/>
)
}
return (
<AnimatedSplashScreen image={image}>
{children}
</AnimatedSplashScreen>
)
}
function AnimatedSplashScreen({ children, image }) {
const animation = React.useMemo(() => new Animated.Value(1), [])
const [isAppReady, setAppReady] = React.useState(false)
const [isSplashAnimationComplete, setAnimationComplete] = React.useState(
false
)
React.useEffect(() => {
if (isAppReady) {
Animated.timing(animation, {
toValue: 0,
duration: 200,
useNativeDriver: true
}).start(() => setAnimationComplete(true))
}
}, [isAppReady])
const onImageLoaded = React.useMemo(() => async () => {
SplashScreen.hide()
try {
// Load stuff
await Promise.all([])
} catch (e) {
// handle errors
} finally {
setAppReady(true)
}
})
return (
<View style={{ flex: 1 }}>
{isAppReady && children}
{!isSplashAnimationComplete && (
<Animated.View
pointerEvents='none'
style={[
StyleSheet.absoluteFill,
{
backgroundColor: Constants.manifest.splash.backgroundColor,
opacity: animation,
justifyContent: 'center',
alignItems: 'center'
}
]}
>
<Animated.Image
style={{
width: '50%',
height: '50%',
resizeMode: Constants.manifest.splash.resizeMode || 'contain',
transform: [
{
scale: animation
}
]
}}
source={require('./img/logo.png')}
onLoadEnd={onImageLoaded}
fadeDuration={0}
/>
</Animated.View>
)}
</View>
)
}