-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
64 lines (52 loc) · 1.7 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
if (__DEV__) {
import("./ReactotronConfig").then(() => console.log("Reactotron Configured"));
}
import {useFonts} from 'expo-font';
import * as SplashScreen from "expo-splash-screen";
import {SafeAreaProvider} from "react-native-safe-area-context";
import {NavigationContainer} from "@react-navigation/native"
import {FONTS} from './src/constants/fonts';
import React, {useCallback, useEffect, useState} from 'react';
import {Provider, useDispatch, useSelector} from 'react-redux'
import store from './store/store'
import {setUser} from "./store/user/actions";
import {getAuth} from "firebase/auth";
import {getFirebaseApp} from "./utils/firebaseHelper";
import {MainNavigator} from "./src/navigation/MainNavigator";
const App = () => {
const dispatch = useDispatch();
const user = useSelector((state) => state.user.user);
const [fontsLoaded] = useFonts(FONTS);
const [navigation, setNavigation] = useState(null);
const onLayoutRootView = useCallback(async () => {
if (fontsLoaded) {
await SplashScreen.hideAsync();
}
}, [fontsLoaded]);
const onAuthStateChanged = (user) => {
dispatch(setUser(user));
};
useEffect(() => {
const app = getFirebaseApp();
const auth = getAuth(app);
return auth.onAuthStateChanged(onAuthStateChanged); // unsubscribe on unmount
}, []);
if (!fontsLoaded) {
return null;
}
return (
<SafeAreaProvider onLayout={onLayoutRootView}>
<NavigationContainer ref={(navigatorRef) => setNavigation(navigatorRef)}>
<MainNavigator user={user}/>
</NavigationContainer>
</SafeAreaProvider>
);
}
const AppWrapper = () => {
return (
<Provider store={store}>
<App/>
</Provider>
)
}
export default AppWrapper;