-
Notifications
You must be signed in to change notification settings - Fork 7
/
App.js
55 lines (43 loc) · 1.19 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
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';
// app context state
import AppState from './src/context/AppState';
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, show app
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 (
<AppState>
<StatusBar barStyle="light-content" />
<RootStack />
<View onLayout={onLayoutRootView} />
</AppState>
);
}
export default App;