-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
124 lines (114 loc) · 3.7 KB
/
App.js
File metadata and controls
124 lines (114 loc) · 3.7 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
import React, { useEffect } from "react";
import { Alert } from "react-native";
//Navigation
import { NavigationContainer } from "@react-navigation/native";
import { createStackNavigator } from "@react-navigation/stack";
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
//Screens
import Categories from "./src/screens/Categories";
import ShoppingCart from "./src/screens/ShoppingCart";
import SplashScreen from "./src/screens/SplashScreen";
import Products from "./src/screens/Products";
import Item from "./src/screens/Item";
import Orders from "./src/screens/Orders";
import UserNav from "./src/components/UserNav";
import { Ionicons } from "@expo/vector-icons";
import { Provider } from "react-redux";
import Store from "./src/state/Store";
import { useSelector } from "react-redux";
import { getCartSummary } from "./src/state/ShoppingCartSlice";
import { loginDetails } from "./src/state/AuthSlice";
import AuthGuardButton from "./src/components/AuthGuardButton";
//Creating navigator objects
const Tabs = createBottomTabNavigator();
const Stack = createStackNavigator();
export default function App() {
const ProductNavigation = ({ navigation }) => {
return (
<Stack.Navigator initialRouteName="ProdCategory">
<Stack.Screen
name="ProdCategory"
component={Categories}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Products"
component={Products}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Item"
component={Item}
options={{ headerShown: false }}
/>
</Stack.Navigator>
);
};
const BottomNavigator = () => {
const { totalQty } = useSelector(getCartSummary);
const { isLoggedIn } = useSelector(loginDetails);
const icon = (name, color = "black", size = 22) => {
return <Ionicons name={name} color={color} size={size} />;
};
return (
<Tabs.Navigator initialRouteName="User Profile">
<Tabs.Screen
name="Product"
component={ProductNavigation}
options={{
tabBarIcon: () => icon("storefront-sharp"),
headerShown: false,
tabBarButton: (props) => <AuthGuardButton {...props} />,
}}
/>
<Tabs.Screen
name="Shopping Cart"
component={ShoppingCart}
options={{
tabBarIcon: () => icon("cart-sharp"),
tabBarButton: (props) => <AuthGuardButton {...props} />,
headerShown: false,
tabBarBadge: totalQty > 0 && isLoggedIn ? totalQty : null,
tabBarBadgeStyle: { color: "white" },
}}
/>
<Tabs.Screen
name="My Orders"
component={Orders}
options={{
tabBarIcon: () => icon("basket"),
tabBarButton: (props) => <AuthGuardButton {...props} />,
headerShown: false,
tabBarBadgeStyle: { color: "white" },
}}
/>
<Tabs.Screen
name="User Profile"
component={UserNav}
options={{
tabBarIcon: () => icon("person-circle-sharp"),
headerShown: false,
}}
/>
</Tabs.Navigator>
);
};
return (
<Provider store={Store}>
<NavigationContainer>
<Stack.Navigator initialRouteName="Home">
<Stack.Screen
name="Home"
component={SplashScreen}
options={{ headerShown: false }}
/>
<Stack.Screen
name="BottomNav"
component={BottomNavigator}
options={{ headerShown: false }}
/>
</Stack.Navigator>
</NavigationContainer>
</Provider>
);
}