-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathApp.js
65 lines (56 loc) · 1.77 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
import RootStack from './src/navigation/RootStack';
import AppState from './src/context';
import { StatusBar, Text, View } from 'react-native';
import { useEffect, useState } from 'react';
import * as SplashScreen from 'expo-splash-screen';
import { loadAsync } from 'expo-font';
import { Asset } from 'expo-asset';
import { savedImages } from './src/constants/preLoadImages';
import { savedFonts } from './src/constants/preLoadFonts';
import { gStyle } from './src/constants';
export default function App() {
const [appIsReady, setAppIsReady] = useState(false);
async function cacheImages() {
for (const images of Object.values(savedImages)) {
await Asset.fromModule(images).downloadAsync();
}
}
async function cacheFonts() {
await loadAsync({
// have to spread the object into the loadAsync function or it will not work
...savedFonts,
});
}
// Load any resources or data that you need prior to rendering the app
useEffect(() => {
async function loadResourcesAndDataAsync() {
try {
SplashScreen.preventAutoHideAsync();
await cacheImages();
await cacheFonts();
console.log('Assets loaded successfully');
} catch (e) {
// You might want to provide this error information to an error reporting service
console.warn(e.message);
} finally {
SplashScreen.hideAsync();
setAppIsReady(true);
}
}
loadResourcesAndDataAsync();
}, []);
if (!appIsReady) {
// Todo: need to add a proper loading screen here
return (
<View style={{ flex: 1, backgroundColor: 'orange' }}>
<Text>Loading Assets...</Text>
</View>
);
}
return (
<AppState>
<StatusBar barStyle="light-content" />
<RootStack />
</AppState>
);
}