-
Notifications
You must be signed in to change notification settings - Fork 14
/
App.js
53 lines (42 loc) · 1.18 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
import * as React from 'react';
import { StatusBar, View } from 'react-native';
import * as SplashScreen from 'expo-splash-screen';
import { func } from './src/constants';
// root stack navigation
import RootStack from './src/navigation/RootStack';
// keeps the splash screen visible while assets are cached
SplashScreen.preventAutoHideAsync();
function App() {
const [isLoading, setIsLoading] = React.useState(true);
React.useEffect(() => {
async function prepare() {
try {
// pre-load/cache assets: images, fonts, and videos
await func.loadAssetsAsync();
} catch (e) {
// console.warn(e);
} finally {
// loading is complete
setIsLoading(false);
}
}
prepare();
}, []);
const onLayoutRootView = React.useCallback(async () => {
if (isLoading === false) {
// loading is complete, hide Splash Screen and show app
await SplashScreen.hideAsync();
}
}, [isLoading]);
if (isLoading) {
return null;
}
return (
<React.Fragment>
<StatusBar barStyle="dark-content" />
<RootStack />
<View onLayout={onLayoutRootView} />
</React.Fragment>
);
}
export default App;