-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
79 lines (63 loc) · 1.98 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import React, { useState, useEffect } from 'react';
import { createAppContainer } from 'react-navigation';
import { AppLoading } from 'expo';
import * as Font from 'expo-font';
import { Asset } from 'expo-asset';
import { Ionicons } from '@expo/vector-icons';
import TabNavigator from './src/TabNavigator';
import ContextProvider from './src/context/Context';
/**
----------
implement switchNavigator for authentication flow:
const switchNavigator = createSwitchNavigator({
AuthScreen,
TabNavigator,
});
const AppContainer = createAppContainer(switchNavigator);
https://reactnavigation.org/docs/en/switch-navigator.html
----------
*/
const AppContainer = createAppContainer(TabNavigator);
/**
----------
Import ALL images and fonts here. Until the loadAssetsAsync Promise is resolved only the AppLoading component will be rendered, which tells Expo to keep the loading screen open. The app will be visible - with all assets preloaded - when that component is removed.
TODO: move isReady to global state?
----------
*/
function cacheImages(images) {
return images.map(image => {
if (typeof image === 'string') {
return Image.prefetch(image);
}
return Asset.fromModule(image).downloadAsync();
});
}
function cacheFonts(fonts) {
return fonts.map(font => Font.loadAsync(font));
}
export default function App() {
const [isReady, setIsReady] = useState(false);
const loadAssetsAsync = async () => {
const imageAssets = cacheImages([]);
const fontAssets = cacheFonts([Ionicons.font, {
'FridgerioPrimaryFont': require('./assets/fonts/Ebrima.ttf'),
}, {
'FridgerioPrimaryFont-Bold': require('./assets/fonts/Ebrima-Bold.ttf'),
}]);
await Promise.all([...imageAssets, ...fontAssets]);
};
if (!isReady) {
return (
<AppLoading
startAsync={loadAssetsAsync}
onFinish={() => setIsReady(true)}
// onError={console.warn}
/>
);
}
return (
<ContextProvider>
<AppContainer />
</ContextProvider>
);
}