-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
62 lines (56 loc) · 1.82 KB
/
App.tsx
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
/* eslint-disable global-require */
import * as Font from 'expo-font';
import * as SplashScreen from 'expo-splash-screen';
import { useCallback, useEffect, useState } from 'react';
import { StyleSheet, View } from 'react-native';
import RootNavigation from './src/navigation/RootNavigator';
async function loadResourcesAsync() {
await Promise.all([
// Pre-load other resources (i.e. images) here
// TODO @david: remove unused font files after global styles are updated
Font.loadAsync({
'DMSans-Bold': require('./assets/fonts/DMSans-Bold.ttf'),
'DMSans-Regular': require('./assets/fonts/DMSans-Regular.ttf'),
}),
]);
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
});
export default function App() {
const [resourcesLoaded, setResourcesLoaded] = useState(false);
/**
* Load any resources or data that we need prior to rendering the app
*/
useEffect(() => {
async function prepare() {
try {
await loadResourcesAsync();
} catch (e) {
// eslint-disable-next-line no-console
console.warn(e);
} finally {
// Tell the application to render
setResourcesLoaded(true);
}
}
prepare();
}, []);
const onLayoutRootView = useCallback(async () => {
if (resourcesLoaded) {
// This tells the splash screen to hide immediately! If we call this after
// `setResourcesLoaded`, then we may see a blank screen while the app is
// loading its initial state and rendering its first pixels. So instead,
// we hide the splash screen once we know the root view has already
// performed layout.
await SplashScreen.hideAsync();
}
}, [resourcesLoaded]);
return !resourcesLoaded ? null : (
<View style={styles.container} onLayout={onLayoutRootView}>
<RootNavigation />
</View>
);
}