-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
212 lines (197 loc) · 6.13 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import React, { useState, useEffect } from "react";
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import Home from "./components/Home";
import Register from "./components/Signup";
import Login from "./components/Login";
import DocHome from "./components/DocHome";
import AsyncStorage from "@react-native-async-storage/async-storage";
import LoadingIndicator from './components/LoadingIndiacator';
import Problems from "./components/PatientProbelms";
import Profile from "./components/Profile";
import { library } from "@fortawesome/fontawesome-svg-core";
import { faHome, faUser, faCog } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-native-fontawesome";
import Settings from "./components/Settings";
import { StyleSheet, View } from "react-native";
import HealthForm from "./components/Form";
import DoConnect from "./components/Doconnect";
library.add(faHome, faUser, faCog);
const Stack = createNativeStackNavigator();
const Tab = createBottomTabNavigator();
export default function App() {
const [initialRoute, setInitialRoute] = useState(null);
const [loading, setLoading] = useState(true);
const [screen, setScreen] = useState(null);
useEffect(() => {
async function checkAuthentication() {
const login = await AsyncStorage.getItem("email");
const category = await AsyncStorage.getItem("category");
if (login) {
setInitialRoute(category === "doctor" ? "DoctorHome" : "UserHome");
setScreen(category === "doctor" ? "MainDoctor" : "MainUser");
} else {
setInitialRoute("Login");
}
setTimeout(() => {
setLoading(false);
}, 3000);
}
checkAuthentication();
}, []);
if (loading) {
return <DoConnect />;
}
return (
<NavigationContainer>
<Stack.Navigator initialRouteName={screen}>
<Stack.Screen options={{ headerShown: false }} name="Login" component={Login} />
<Stack.Screen options={{ headerShown: false }} name="Register" component={Register} />
<Stack.Screen options={{ headerShown: false }} name="MainDoctor">
{() => <MainDoctor initialRoute={initialRoute} />}
</Stack.Screen>
<Stack.Screen options={{ headerShown: false }} name="MainUser">
{() => <MainUser initialRoute={initialRoute} />}
</Stack.Screen>
</Stack.Navigator>
</NavigationContainer>
);
}
function MainDoctor({ initialRoute }) {
return (
<Tab.Navigator
initialRouteName="Home"
screenOptions={({ route }) => ({
tabBarIcon: ({ color, size }) => {
let iconName;
if (route.name === "Home") {
iconName = faHome;
} else if (route.name === "Profile") {
iconName = faUser;
} else if (route.name === "Settings") {
iconName = faCog;
}
return (
<FontAwesomeIcon icon={iconName} size={size} color={color} />
);
},
})}
tabBarOptions={{
activeTintColor: "#123457",
labelStyle: {
fontSize: 14,
fontWeight: "bold",
},
tabStyle: {
borderRadius: 50,
},
activeBackgroundColor: "#ececec",
}}
>
<Tab.Screen name="Home" options={{ headerShown: false }}>
{() => <HomeDoctorScreen initialRoute={initialRoute} />}
</Tab.Screen>
<Tab.Screen name="Profile" component={ProfileStackScreen} />
<Tab.Screen name="Settings" component={SettingsStackScreen} />
</Tab.Navigator>
);
}
function MainUser({ initialRoute }) {
return (
<Tab.Navigator
initialRouteName="Home"
screenOptions={({ route }) => ({
tabBarIcon: ({ color, size }) => {
let iconName;
if (route.name === "Home") {
iconName = faHome;
} else if (route.name === "Profile") {
iconName = faUser;
} else if (route.name === "Settings") {
iconName = faCog;
}
return (
<FontAwesomeIcon icon={iconName} size={size} color={color} />
);
},
})}
tabBarOptions={{
activeTintColor: "#123457",
labelStyle: {
fontSize: 14,
fontWeight: "bold",
},
tabStyle: {
borderRadius: 50,
},
activeBackgroundColor: "#ececec",
}}
>
<Tab.Screen name="Home" options={{ headerShown: false }}>
{() => <HomeUserScreen initialRoute={initialRoute} />}
</Tab.Screen>
<Tab.Screen name="Profile" component={ProfileStackScreen} />
<Tab.Screen name="Settings" component={SettingsStackScreen} />
</Tab.Navigator>
);
}
function HomeUserScreen({ initialRoute }) {
return (
<Stack.Navigator initialRouteName={initialRoute}>
<Stack.Screen
name="UserHome"
component={Home}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Form"
component={HealthForm}
options={{ headerShown: false }}
/>
</Stack.Navigator>
);
}
function HomeDoctorScreen({ initialRoute }) {
return (
<Stack.Navigator initialRouteName={initialRoute}>
<Stack.Screen
name="DoctorHome"
component={DocHome}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Problems"
component={Problems}
options={{ headerShown: false }}
/>
</Stack.Navigator>
);
}
function ProfileStackScreen() {
return (
<Stack.Navigator initialRouteName="ProfilePage">
<Stack.Screen
name="ProfilePage"
component={Profile}
options={{ headerShown: false }}
/>
<Stack.Screen
name="editProfile"
component={Profile}
options={{ headerShown: false }}
/>
</Stack.Navigator>
);
}
function SettingsStackScreen() {
return (
<Stack.Navigator initialRouteName="SettingsPage">
<Stack.Screen
name="SettingsPage"
component={Settings}
options={{ headerShown: false }}
/>
</Stack.Navigator>
);
}