-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathApp.js
76 lines (68 loc) · 2.11 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
65
66
67
68
69
70
71
72
73
74
75
76
import { useEffect, useState } from "react";
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { View, ActivityIndicator } from "react-native";
import Splash from "./src/screens/Splash";
import Login from "./src/screens/#";
import # from "./src/screens/#";
import AuthContext from "./AuthContext";
import BottomTabNavigation from "./src/BottomTabNavigation";
import PatientDetails from "./src/screens/PatientDetails";
import { auth } from "./firebaseConfig";
const Stack = createNativeStackNavigator();
export default function App() {
const [user, setUser] = useState("");
const [loader, setLoader] = useState(true);
useEffect(() => {
auth.onAuthStateChanged((user) => {
if (user) {
console.log("User is signed in");
setUser(user.uid);
setLoader(false);
} else {
console.log("User is not signed in");
setLoader(false);
}
});
}, []);
function signin(newUser, callback) {
setUser(newUser);
callback();
}
function signout() {
setUser(null);
}
let value = { user, signin, signout };
if (loader) {
return (
<View
style={{
height: "100%",
width: "100%",
justifyContent: "center",
alignItems: "center",
}}
>
<ActivityIndicator animating={loader} size="large" />
</View>
);
}
return (
<AuthContext.Provider value={value}>
<NavigationContainer>
<Stack.Navigator
initialRouteName={user?.length > 0 ? "BottomTab" : "Splash"}
screenOptions={{
headerShown: false,
}}
>
<Stack.Screen name="Splash" component={Splash} />
<Stack.Screen name="Login" component={Login} />
<Stack.Screen name="#" component={#} />
<Stack.Screen name="BottomTab" component={BottomTabNavigation} />
<Stack.Screen name="PatientDetails" component={PatientDetails} />
</Stack.Navigator>
</NavigationContainer>
</AuthContext.Provider>
);
}