-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
179 lines (156 loc) · 4.96 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
import React, { useEffect } from "react";
import { NavigationContainer } from "@react-navigation/native";
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import { createStackNavigator } from "@react-navigation/stack";
import HomeScreen from "./screens/HomeScreen";
import RecipeDetailsScreen from "./screens/RecipeDetailsScreen";
import RecipeSearchScreen from "./screens/RecipeSearchScreen";
import AddRecipeScreen from "./screens/AddRecipeScreen";
import UserScreen from "./screens/UserScreen";
import MealPlanningScreen from "./screens/MealPlanningScreen";
import RecipeCollectionsScreen from "./screens/RecipeCollectionsScreen";
import FavoritesScreen from "./screens/FavouritesScreen";
import GroceryListScreen from "./screens/GroceryListScreen";
import LoginScreen from "./screens/LoginScreen";
import { useState } from "react";
import { onAuthStateChanged } from "firebase/auth";
import { auth } from "./firebase";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { Alert } from "react-native";
import CookingScreen from "./screens/CookingScreen";
import { StatusBar } from "react-native";
import Icon from 'react-native-vector-icons/Ionicons'; // Import icons
import { theme } from "./Theme";
const Stack = createStackNavigator();
const Tab = createBottomTabNavigator();
const UserStack = () => (
<Stack.Navigator>
<Stack.Screen
name="User"
component={UserScreen}
options={{ headerShown: false }}
/>
<Stack.Screen name="MealPlanning" component={MealPlanningScreen} />
<Stack.Screen
name="RecipeCollections"
component={RecipeCollectionsScreen}
/>
<Stack.Screen name="Favorites" component={FavoritesScreen} />
<Stack.Screen name="GroceryList" component={GroceryListScreen} />
</Stack.Navigator>
);
const MainStack = createStackNavigator();
const color = theme.colors.primary;
const MainTabNavigator = () => (
<Tab.Navigator
// active tab col
>
<Tab.Screen
name="Home"
component={HomeScreen}
options={{
headerShown: false,
tabBarIcon: ({ color, size }) => (
<Icon name="home-outline" color={theme.colors.primary} size={size} />
),
tabBarHideOnKeyboard: true,
tabBarLabelStyle: {display: 'none'},
}}
tabBarOptions={{
activeTintColor: '#90D26D', // Color for the selected tab icon
inactiveTintColor: '#999999', // Color for the unselected tab icons
}}
/>
<Tab.Screen
name="RecipeSearch"
component={RecipeSearchScreen}
options={{
headerShown: false,
tabBarIcon: ({ color, size }) => (
<Icon name="search-outline" color={color} size={size} />
),
tabBarHideOnKeyboard: true,
tabBarLabelStyle: {display: 'none'},
}}
/>
<Tab.Screen
name="AddRecipe"
component={AddRecipeScreen}
options={{
headerShown: false,
tabBarIcon: ({ color, size }) => (
<Icon name="add-circle-outline" color={color} size={size} />
),
tabBarHideOnKeyboard: true,
tabBarLabelStyle: {display: 'none'},
}}
/>
<Tab.Screen
name="User"
component={UserStack}
options={{
headerShown: false,
tabBarIcon: ({ color, size }) => (
<Icon name="person-outline" color={color} size={size} />
),
tabBarHideOnKeyboard: true,
tabBarLabelStyle: {display: 'none'},
}}
/>
</Tab.Navigator>
);
export default function App() {
const [user, setUser] = useState(null);
const checkLocalUser = async () => {
try {
const user = await AsyncStorage.getItem("user");
if (user) {
setUser(JSON.parse(user));
}
} catch (error) {
console.error(error);
}
};
useEffect(() => {
checkLocalUser();
const unsubscribe = onAuthStateChanged(auth, async (user) => {
setUser(user);
AsyncStorage.setItem("user", JSON.stringify(user));
});
return unsubscribe;
}, []);
return (
<NavigationContainer>
<StatusBar barStyle="dark-content" />
<MainStack.Navigator
screenOptions={{
user: user, // Pass the user state to all screens
}}
>
{user ? (
<MainStack.Screen
name="MainTabs"
component={MainTabNavigator}
options={{ headerShown: false }}
/>
) : (
<MainStack.Screen
name="Login"
component={LoginScreen}
options={{ headerShown: false }}
/>
)}
<MainStack.Screen
name="RecipeDetails"
component={RecipeDetailsScreen}
options={{ headerShown: false }}
/>
<MainStack.Screen
name="CookingScreen"
component={CookingScreen}
options={{ headerShown: true, headerTitle: "Cook" }}
/>
</MainStack.Navigator>
</NavigationContainer>
);
}