This repository has been archived by the owner on Nov 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
61 lines (52 loc) · 1.5 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 React from 'react'
import { Image, Platform, View, StatusBar } from 'react-native'
import { AppLoading, SplashScreen } from 'expo'
import { Asset } from 'expo-asset'
import AppNavigator from './src/navigation/AppNavigator'
export default class App extends React.Component {
state = {
isSplashReady: false,
isAppReady: false,
}
render() {
if (!this.state.isSplashReady) {
return (
<AppLoading
startAsync={this._cacheSplashResourcesAsync}
onFinish={() => this.setState({ isSplashReady: true })}
onError={console.warn}
autoHideSplash={false}
/>
)
}
if (!this.state.isAppReady) {
return (
<View style={{ flex: 1 }}>
<Image source={require('./src/assets/splash.png')} onLoad={this._cacheResourcesAsync} />
</View>
)
}
return (
<View style={{ flex: 1 }}>
{Platform.OS === 'ios' && <StatusBar barStyle="default" />}
<AppNavigator />
</View>
)
}
_cacheSplashResourcesAsync = async () => {
const splash = require('./src/assets/splash.png')
return Asset.fromModule(splash).downloadAsync()
}
_cacheResourcesAsync = async () => {
SplashScreen.hide()
const images = [
// Insert prefetching shit here
// require('EXAMPLE IMAGE PATH'),
]
const cacheImages = images.map(image => {
return Asset.fromModule(image).downloadAsync()
})
await Promise.all(cacheImages)
this.setState({ isAppReady: true })
}
}