-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
55 lines (47 loc) · 1.66 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
import React, { Suspense, useState, useEffect, lazy } from "react";
import { ActivityIndicator, View } from "react-native";
import { Provider } from "react-redux";
import { NavigationContainer } from "@react-navigation/native";
import store from "./store";
import { createStackNavigator } from "@react-navigation/stack";
import { getAuth, onAuthStateChanged } from "firebase/auth";
const Stack = createStackNavigator();
const auth = getAuth();
const LandingPage = lazy(() => import("./screens/LandingScreen"));
const Main = lazy(() => import("./screens/MainComponent"));
const LoginScreen = lazy(() => import("./screens/LoginScreen"));
const App = () => {
const [isLoggedIn, setIsLoggedIn] = useState(false);
const [loading, setLoading] = useState(true);
useEffect(() => {
const unsubscribe = onAuthStateChanged(auth, (user) => {
setIsLoggedIn(!!user);
setLoading(false);
});
return unsubscribe;
}, []);
if (loading) {
return (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<ActivityIndicator />
</View>
);
}
return (
<Provider store={store}>
<NavigationContainer>
<Suspense fallback={<ActivityIndicator />}>
<Stack.Navigator
initialRouteName={isLoggedIn ? "Main" : "Landing"}
screenOptions={{ headerShown: false }}
>
<Stack.Screen name="Landing" component={LandingPage} />
<Stack.Screen name="Login" component={LoginScreen} />
<Stack.Screen name="Main" component={Main} />
</Stack.Navigator>
</Suspense>
</NavigationContainer>
</Provider>
);
};
export default App;