-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
64 lines (56 loc) · 1.78 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
import React, { useEffect, useState } from 'react';
import * as SplashScreen from 'expo-splash-screen';
import * as Font from 'expo-font';
import { Ionicons } from '@expo/vector-icons';
import { Image, useColorScheme } from 'react-native';
import { Asset } from 'expo-asset';
import { NavigationContainer } from '@react-navigation/native';
import Root from './navigation/Root';
import { DarkTheme, lightTheme } from './theme';
import { ThemeProvider } from 'styled-components/native';
import { QueryClient, QueryClientProvider } from 'react-query';
// Keep the splash screen visible while we fetch resources
SplashScreen.preventAutoHideAsync();
const queryClient = new QueryClient();
const loadFonts = (fonts) => fonts.map((font) => Font.loadAsync(font));
const loadImages = (images) =>
images.map((image) => {
if (typeof image === 'string') {
return Image.prefetch(image);
} else {
return Asset.loadAsync(image);
}
});
export default function App() {
const [ready, setReady] = useState(false);
useEffect(() => {
async function prepare() {
try {
// Pre-load fonts, make any API calls you need to do here
const fonts = loadFonts([Ionicons.font]);
const assets = loadImages(['https://reactnative.dev/img/oss_logo.svg']);
await Promise.all([...fonts, ...assets]);
} catch (e) {
// console.warn(e);
} finally {
setReady(true);
SplashScreen.hideAsync();
}
}
prepare();
}, []);
const isDark = useColorScheme() === 'dark';
// launch screen remain visible until it has been explicitly told hide
if (!ready) {
return null;
}
return (
<QueryClientProvider client={queryClient}>
<ThemeProvider theme={isDark ? DarkTheme : lightTheme}>
<NavigationContainer>
<Root />
</NavigationContainer>
</ThemeProvider>
</QueryClientProvider>
);
}