-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
72 lines (65 loc) · 2.39 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
63
64
65
66
67
68
69
70
71
72
/* eslint-disable global-require */
import * as Font from 'expo-font';
import * as SplashScreen from 'expo-splash-screen';
import React, { useCallback, useEffect, useState } from 'react';
import { StyleSheet, View } from 'react-native';
import AppNavigator from './src/navigation/AppNavigator';
import { AuthContextProvider } from './src/screens/auth/AuthContext';
// Keep the splash screen visible while we fetch resources
SplashScreen.preventAutoHideAsync();
async function loadResourcesAsync() {
await Promise.all([
// Pre-load other resources (i.e. images) here
Font.loadAsync({
'manrope-bold': require('./assets/Manrope/static/Manrope-Bold.ttf'),
'manrope-extraBold': require('./assets/Manrope/static/Manrope-ExtraBold.ttf'),
'manrope-extraLight': require('./assets/Manrope/static/Manrope-ExtraLight.ttf'),
'manrope-light': require('./assets/Manrope/static/Manrope-Light.ttf'),
'manrope-medium': require('./assets/Manrope/static/Manrope-Medium.ttf'),
'manrope-regular': require('./assets/Manrope/static/Manrope-Regular.ttf'),
'manrope-semiBold': require('./assets/Manrope/static/Manrope-SemiBold.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}>
<AuthContextProvider>
<AppNavigator />
</AuthContextProvider>
</View>
);
}