-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
41 lines (36 loc) · 1.19 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
import React, { useState } from "react";
import { AppLoading } from "expo";
import { Image, StatusBar } from "react-native";
import * as Font from "expo-font";
import { Asset } from "expo-asset";
import { Ionicons } from "@expo/vector-icons";
import { NavigationContainer } from "@react-navigation/native";
import Stack from "./navigation/Stack";
const cacheImages = (images) =>
images.map((image) => {
if (typeof image === "string") {
return Image.prefetch(image);
} else {
return Asset.fromModule(image).downloadAsync();
}
});
const cacheFonts = (fonts) => fonts.map((font) => Font.loadAsync(font));
export default function App() {
const [isReady, setIsReady] = useState(false);
const loadAssets = async () => {
const images = cacheImages([require("./assets/splash.png")]);
const fonts = cacheFonts([Ionicons.font]);
return Promise.all([...images, ...fonts]);
};
const onFinish = () => setIsReady(true);
return isReady ? (
<>
<NavigationContainer>
<Stack />
</NavigationContainer>
<StatusBar barStyle="light-content" />
</>
) : (
<AppLoading startAsync={loadAssets} onFinish={onFinish} onError={console.error} />
);
}