-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
54 lines (43 loc) · 1.23 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
import React from "react";
import { ActivityIndicator , StyleSheet ,View} from "react-native";
import { Asset } from 'expo-asset';
import OnBoarding from "./src/OnBoarding";
function cacheImages(images) {
return images.map(image => {
if (typeof image === 'string') {
return Image.prefetch(image);
} else {
return Asset.fromModule(image).downloadAsync();
}
});
}
export default function App() {
const [appIsReady, setAppIsReady] = React.useState(false);
const loadAssetsAsync = async () => {
const imageAssets = cacheImages([
require('./assets/bg1.jpeg'), require('./assets/bg2.jpg')
]);
await Promise.all([...imageAssets]);
}
React.useEffect(()=>{
(async () => {
try {
await loadAssetsAsync();
// Artificially delay for two seconds to simulate a slow loading
await new Promise(resolve => setTimeout(resolve, 200));
} catch (e) {
console.warn(e);
} finally {
setAppIsReady(true);
}
})()
} ,[])
return (
<>
{appIsReady ? <OnBoarding/> : <View style={{...StyleSheet.absoluteFill , alignItems : 'center' , justifyContent:'center'}}>
<ActivityIndicator/>
</View>
}
</>
);
}