-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathApp.js
More file actions
71 lines (65 loc) · 2.21 KB
/
Copy pathApp.js
File metadata and controls
71 lines (65 loc) · 2.21 KB
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
import React, { useEffect } from "react";
import { Text } from "react-native";
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { onAuthStateChanged, getAuth } from "@firebase/auth";
import { checkNewuser } from "./firebase";
import { UserProvider } from "./context/context";
import Login from "./components/Login";
import SignUp from "./components/SignUp";
import Profile from "./components/Profile";
import Chats from "./components/Chats";
import DrawerNavigation from "./components/Navigation";
export default function App() {
const [user, setUser] = React.useState(false);
const [isLoading, setIsLoading] = React.useState(true);
const auth = getAuth();
const Stack = createNativeStackNavigator();
// check if user is loggen into firebase
useEffect(() => {
console.log(auth.currentUser);
setIsLoading(true);
checkNewuser().then((u) => {
setUser(u);
});
setIsLoading(false);
}, []);
if (isLoading) return <Text>Loading...</Text>;
return (
<>
<UserProvider>
<NavigationContainer>
<Stack.Navigator>
{!user ? (
<>
<Stack.Screen
name="Login"
component={Login}
options={{ headerShown: false }}
initialParams={{ newUser: setUser }}
/>
<Stack.Screen name="Sign Up" component={SignUp} options={{ headerShown: false }}/>
<Stack.Screen
name="Profile"
component={Profile}
options={{ headerShown: false }}
initialParams={{ newUser: setUser }}
/>
</>
) : (
<>
<Stack.Screen
name="navigator"
component={DrawerNavigation}
options={{ headerShown: false }}
initialParams={{ newUser: setUser }}
/>
<Stack.Screen name="Chats" component={Chats}></Stack.Screen>
</>
)}
</Stack.Navigator>
</NavigationContainer>
</UserProvider>
</>
);
}