-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathApp.js
50 lines (47 loc) · 1.49 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
import React, { useState } from "react";
import { AppLoading } from "expo";
import { Asset } from "expo-asset";
import * as Font from "expo-font";
import { Ionicons } from "@expo/vector-icons";
import { Image } from "react-native";
import { Provider } from "react-redux";
import { PersistGate } from "redux-persist/integration/react";
import Gate from "./components/Gate";
import store, { persistor } from "./redux/store";
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 handleFinish = () => setIsReady(true);
const loadAssets = async () => {
const images = [
require("./assets/loginBg.jpeg"),
require("./assets/roomDefault.jpeg"),
"http://logok.org/wp-content/uploads/2014/07/airbnb-logo-belo-219x286.png"
];
const fonts = [Ionicons.font];
const imagePromises = cacheImages(images);
const fontPromises = cacheFonts(fonts);
return Promise.all([...fontPromises, ...imagePromises]);
};
return isReady ? (
<Provider store={store}>
<PersistGate persistor={persistor}>
<Gate />
</PersistGate>
</Provider>
) : (
<AppLoading
onError={console.error}
onFinish={handleFinish}
startAsync={loadAssets}
/>
);
}