-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
174 lines (164 loc) · 5.07 KB
/
Copy pathApp.tsx
File metadata and controls
174 lines (164 loc) · 5.07 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
import React, { useEffect, useState } from 'react';
import { View, Text, ActivityIndicator } from 'react-native';
import { StatusBar } from 'expo-status-bar';
import { NavigationContainer, DefaultTheme as NavDefaultTheme } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { PaperProvider } from 'react-native-paper';
import { MaterialCommunityIcons } from '@expo/vector-icons';
import { HomeScreen } from './src/screens/HomeScreen';
import { ResultScreen } from './src/screens/ResultScreen';
import { HistoryScreen } from './src/screens/HistoryScreen';
import { TextInputScreen } from './src/screens/TextInputScreen';
import { ManualEntryScreen } from './src/screens/ManualEntryScreen';
import { OnboardingScreen } from './src/screens/OnboardingScreen';
import { SettingsScreen } from './src/screens/SettingsScreen';
import { useAppStore } from './src/store/appStore';
import { theme } from './src/theme';
// Navigation types
export type RootStackParamList = {
Onboarding: undefined;
Home: undefined;
Result: undefined;
History: undefined;
TextInput: undefined;
ManualEntry: undefined;
Settings: undefined;
};
const Stack = createNativeStackNavigator<RootStackParamList>();
// Custom navigation theme
const CalTrackTheme = {
...NavDefaultTheme,
colors: {
...NavDefaultTheme.colors,
background: theme.colors.background,
card: theme.colors.surface,
text: theme.colors.onSurface,
primary: theme.colors.primary,
border: theme.colors.outline,
},
};
// Loading screen while database initializes
const LoadingScreen = () => (
<View style={{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: theme.colors.background
}}>
<Text style={{
fontSize: 48,
marginBottom: 20
}}>🍛</Text>
<Text style={{
color: theme.colors.primary,
fontSize: 24,
fontWeight: 'bold',
marginBottom: 16
}}>CalTrack</Text>
<ActivityIndicator size="large" color={theme.colors.primary} />
<Text style={{
color: theme.colors.onSurfaceVariant,
marginTop: 16
}}>Loading your food log...</Text>
</View>
);
export default function App() {
const { isDbInitialized, isOnboardingComplete, initializeDatabase } = useAppStore();
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {
const init = async () => {
await initializeDatabase();
setIsLoading(false);
};
init();
}, []);
if (isLoading || !isDbInitialized) {
return (
<SafeAreaProvider>
<LoadingScreen />
<StatusBar style="dark" />
</SafeAreaProvider>
);
}
return (
<SafeAreaProvider>
<PaperProvider theme={theme} settings={{ icon: props => <MaterialCommunityIcons {...props} /> }}>
<NavigationContainer theme={CalTrackTheme}>
<StatusBar style="dark" />
<Stack.Navigator
initialRouteName={isOnboardingComplete ? "Home" : "Onboarding"}
screenOptions={{
headerStyle: {
backgroundColor: theme.colors.surface,
},
headerTintColor: theme.colors.primary,
headerTitleStyle: {
fontWeight: '600',
},
headerShadowVisible: false,
contentStyle: {
backgroundColor: theme.colors.background,
},
}}
>
<Stack.Screen
name="Onboarding"
component={OnboardingScreen}
options={{
headerShown: false,
}}
/>
<Stack.Screen
name="Home"
component={HomeScreen}
options={{
headerShown: false,
}}
/>
<Stack.Screen
name="Result"
component={ResultScreen}
options={{
title: 'Analysis',
headerBackTitle: 'Back',
}}
/>
<Stack.Screen
name="History"
component={HistoryScreen}
options={{
title: 'Food History',
headerBackTitle: 'Back',
}}
/>
<Stack.Screen
name="TextInput"
component={TextInputScreen}
options={{
title: 'Describe Food',
headerBackTitle: 'Back',
}}
/>
<Stack.Screen
name="ManualEntry"
component={ManualEntryScreen}
options={{
title: 'Manual Entry',
headerBackTitle: 'Back',
}}
/>
<Stack.Screen
name="Settings"
component={SettingsScreen}
options={{
title: 'Settings',
headerBackTitle: 'Back',
}}
/>
</Stack.Navigator>
</NavigationContainer>
</PaperProvider>
</SafeAreaProvider>
);
}