-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
83 lines (69 loc) · 2.07 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
73
74
75
76
77
78
79
80
81
82
83
import 'react-native-gesture-handler';
import React, { useEffect, useState } from 'react';
import { Quicksand_400Regular, Quicksand_700Bold } from '@expo-google-fonts/quicksand';
import auth, { FirebaseAuthTypes } from '@react-native-firebase/auth';
import { NavigationContainer } from '@react-navigation/native';
import { ThemeProvider } from '@rneui/themed';
import { QueryClientProvider } from '@tanstack/react-query';
import { persistQueryClient } from '@tanstack/react-query-persist-client';
import * as Font from 'expo-font';
import * as SplashScreen from 'expo-splash-screen';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { asyncStoragePersister, queryClient } from '@app/data';
import { stackNavigation } from '@app/navigation';
import { ClearTheme, FontFamily } from '@app/styles';
const Screens = () => {
const [appIsReady, setAppIsReady] = useState(false);
const [authReady, setAuthReady] = useState(false);
const [user, setUser] = useState<FirebaseAuthTypes.User | null>();
useEffect(() => {
const unsubscribe = auth().onAuthStateChanged(user => {
setUser(user);
setAuthReady(true);
});
return unsubscribe;
}, []);
useEffect(() => {
async function prepare() {
try {
await Font.loadAsync({
[FontFamily.REGULAR]: Quicksand_400Regular,
[FontFamily.BOLD]: Quicksand_700Bold
});
} catch (e) {
console.warn(e);
} finally {
setAppIsReady(true);
}
}
prepare();
}, []);
useEffect(() => {
async function hide() {
await SplashScreen.hideAsync();
}
if (appIsReady && authReady) {
hide();
}
}, [appIsReady, authReady]);
if (!appIsReady || !authReady) {
return null;
}
return <NavigationContainer>{stackNavigation(user)}</NavigationContainer>;
};
SplashScreen.preventAutoHideAsync();
persistQueryClient({
queryClient,
persister: asyncStoragePersister
});
export default function App() {
return (
<SafeAreaProvider>
<QueryClientProvider client={queryClient}>
<ThemeProvider theme={ClearTheme}>
<Screens />
</ThemeProvider>
</QueryClientProvider>
</SafeAreaProvider>
);
}