forked from calebnance/expo-uber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
55 lines (44 loc) · 1.21 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 } from 'react-native';
import * as SplashScreen from 'expo-splash-screen';
import { func } from './src/constants';
// root stack navigation
import RootStack from './src/navigation/RootStack';
const 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 (
<React.Fragment>
<StatusBar barStyle="dark-content" />
<RootStack />
</React.Fragment>
);
};
export default App;