-
Notifications
You must be signed in to change notification settings - Fork 104
/
App.js
58 lines (46 loc) · 1.26 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
import * as React from 'react';
import { StatusBar } 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';
function App() {
const [isLoading, setIsLoading] = React.useState(true);
React.useEffect(() => {
async function prepare() {
try {
// keeps the splash screen visible while assets are cached
await SplashScreen.preventAutoHideAsync();
// pre-load/cache assets: images, fonts, and videos
await func.loadAssetsAsync();
} catch (e) {
// console.warn(e);
} finally {
// loading is complete
setIsLoading(false);
}
}
prepare();
}, []);
React.useEffect(() => {
// when loading is complete
if (isLoading === false) {
// hide splash function
const hideSplash = async () => SplashScreen.hideAsync();
// hide splash screen to show app
hideSplash();
}
}, [isLoading]);
if (isLoading) {
return null;
}
return (
<AppState>
<StatusBar barStyle="light-content" />
<RootStack />
</AppState>
);
}
export default App;