-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
256 lines (230 loc) · 8.33 KB
/
Copy pathApp.tsx
File metadata and controls
256 lines (230 loc) · 8.33 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
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
import React, { useEffect, useState } from 'react';
import { View, ActivityIndicator } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
import { Provider as PaperProvider } from 'react-native-paper';
import { SafeAreaProvider, useSafeAreaInsets } from 'react-native-safe-area-context';
// Screens — Shared
import ModeSelection from './src/screens/ModeSelection';
import SessionDetail from './src/screens/SessionDetail';
// Screens — Patient
import PatientWelcome from './src/screens/PatientWelcome';
import LiveMonitor from './src/screens/LiveMonitor';
import History from './src/screens/History';
import Pills from './src/screens/Pills';
import Settings from './src/screens/Settings';
// Screens — Doctor
import DoctorDashboard from './src/screens/DoctorDashboard';
import PatientList from './src/screens/PatientList';
import PatientDetail from './src/screens/PatientDetail';
import AddPatient from './src/screens/AddPatient';
// Screens — Researcher
import ResearchDashboard from './src/screens/ResearchDashboard';
import ResearchExport from './src/screens/ResearchExport';
// Services
import DatabaseService from './src/services/DatabaseService';
import FirebaseService from './src/services/FirebaseService';
import { colors, icons } from './src/theme';
const Stack = createNativeStackNavigator();
const Tab = createBottomTabNavigator();
// Hook that builds tab options with bottom safe-area inset baked in.
// This pushes the tab bar above the Android gesture bar / navigation pill.
const useTabScreenOptions = () => {
const insets = useSafeAreaInsets();
return {
tabBarActiveTintColor: colors.primary,
tabBarInactiveTintColor: colors.textTertiary,
tabBarStyle: {
backgroundColor: colors.surface,
borderTopColor: colors.border,
paddingTop: 6,
paddingBottom: 6 + insets.bottom,
height: 62 + insets.bottom,
},
tabBarLabelStyle: {
fontSize: 11,
fontWeight: '600',
},
headerStyle: {
backgroundColor: colors.surface,
},
headerTitleStyle: {
fontWeight: '700',
color: colors.textPrimary,
},
headerShadowVisible: false,
};
};
// ============ PATIENT ============
function PatientTabs() {
const baseOptions = useTabScreenOptions();
return (
<Tab.Navigator
screenOptions={({ route }) => ({
...baseOptions,
tabBarIcon: ({ color, size }) => {
const name = {
Live: icons.live,
History: icons.history,
Pills: icons.pills,
Settings: icons.settings,
}[route.name] || 'circle';
return <MaterialCommunityIcons name={name} size={size} color={color} />;
},
})}
>
<Tab.Screen name="Live" component={LiveMonitor} options={{ headerShown: false }} />
<Tab.Screen name="History" component={History} options={{ title: 'Session History' }} />
<Tab.Screen name="Pills" component={Pills} options={{ title: 'Medication' }} />
<Tab.Screen name="Settings" component={Settings} options={{ title: 'Settings' }} />
</Tab.Navigator>
);
}
function PatientStack() {
return (
<Stack.Navigator screenOptions={{ headerShadowVisible: false }}>
<Stack.Screen name="PatientWelcome" component={PatientWelcome} options={{ headerShown: false }} />
<Stack.Screen name="PatientTabs" component={PatientTabs} options={{ headerShown: false }} />
<Stack.Screen
name="SessionDetail"
component={SessionDetail}
options={{ title: 'Session Details', headerBackTitle: 'Back' }}
/>
</Stack.Navigator>
);
}
// ============ DOCTOR ============
function DoctorTabs() {
const baseOptions = useTabScreenOptions();
return (
<Tab.Navigator
screenOptions={({ route }) => ({
...baseOptions,
tabBarIcon: ({ color, size }) => {
const name = {
Dashboard: icons.dashboard,
Patients: icons.patients,
DoctorSettings: icons.settings,
}[route.name] || 'circle';
return <MaterialCommunityIcons name={name} size={size} color={color} />;
},
})}
>
<Tab.Screen name="Dashboard" component={DoctorDashboard} options={{ title: 'Dashboard' }} />
<Tab.Screen name="Patients" component={PatientList} options={{ title: 'Patients' }} />
<Tab.Screen
name="DoctorSettings"
component={Settings}
options={{ title: 'Settings' }}
/>
</Tab.Navigator>
);
}
function DoctorStack() {
return (
<Stack.Navigator screenOptions={{ headerShadowVisible: false }}>
<Stack.Screen name="DoctorTabs" component={DoctorTabs} options={{ headerShown: false }} />
<Stack.Screen
name="PatientDetail"
component={PatientDetail}
options={({ route }) => {
const params = route.params as { patientName?: string };
return { title: params?.patientName || 'Patient' };
}}
/>
<Stack.Screen
name="AddPatient"
component={AddPatient}
options={{ title: 'Add Patient' }}
/>
<Stack.Screen
name="SessionDetail"
component={SessionDetail}
options={{ title: 'Session Details' }}
/>
</Stack.Navigator>
);
}
// ============ RESEARCHER ============
function ResearcherTabs() {
const baseOptions = useTabScreenOptions();
return (
<Tab.Navigator
screenOptions={({ route }) => ({
...baseOptions,
tabBarIcon: ({ color, size }) => {
const name = {
Overview: icons.research,
Export: icons.export,
ResearcherSettings: icons.settings,
}[route.name] || 'circle';
return <MaterialCommunityIcons name={name} size={size} color={color} />;
},
})}
>
<Tab.Screen name="Overview" component={ResearchDashboard} options={{ title: 'Research' }} />
<Tab.Screen name="Export" component={ResearchExport} options={{ title: 'Data Export' }} />
<Tab.Screen
name="ResearcherSettings"
component={Settings}
options={{ title: 'Settings' }}
/>
</Tab.Navigator>
);
}
function ResearcherStack() {
return (
<Stack.Navigator screenOptions={{ headerShadowVisible: false }}>
<Stack.Screen name="ResearcherTabs" component={ResearcherTabs} options={{ headerShown: false }} />
</Stack.Navigator>
);
}
// ============ ROOT ============
function App() {
const [initialRoute, setInitialRoute] = useState<string | null>(null);
const [isReady, setIsReady] = useState(false);
useEffect(() => { initializeApp(); }, []);
const initializeApp = async () => {
try {
await DatabaseService.initDatabase();
// Try to flush anything pending in the sync queue on launch
FirebaseService.processSyncQueue().catch(() => {});
const savedMode = await DatabaseService.getSetting('app_mode', null);
if (savedMode === 'patient') setInitialRoute('PatientApp');
else if (savedMode === 'doctor') setInitialRoute('DoctorApp');
else if (savedMode === 'researcher') setInitialRoute('ResearcherApp');
else setInitialRoute('ModeSelection');
setIsReady(true);
} catch (error) {
console.error('App init error:', error);
setInitialRoute('ModeSelection');
setIsReady(true);
}
};
if (!isReady || !initialRoute) {
return (
<SafeAreaProvider>
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center', backgroundColor: colors.background }}>
<ActivityIndicator size="large" color={colors.primary} />
</View>
</SafeAreaProvider>
);
}
return (
<SafeAreaProvider>
<PaperProvider>
<NavigationContainer>
<Stack.Navigator initialRouteName={initialRoute} screenOptions={{ headerShown: false }}>
<Stack.Screen name="ModeSelection" component={ModeSelection} />
<Stack.Screen name="PatientApp" component={PatientStack} />
<Stack.Screen name="DoctorApp" component={DoctorStack} />
<Stack.Screen name="ResearcherApp" component={ResearcherStack} />
</Stack.Navigator>
</NavigationContainer>
</PaperProvider>
</SafeAreaProvider>
);
}
export default App;