-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnavigation.js
218 lines (206 loc) · 5.49 KB
/
navigation.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
213
214
215
216
217
218
import {StyleSheet, Text, View} from 'react-native';
import React, {useEffect, useState} from 'react';
import {NavigationContainer} from '@react-navigation/native';
import {createNativeStackNavigator} from '@react-navigation/native-stack';
import HomeScreen from './src/pages/Home/HomeScreen';
import {COLORS} from './src/constant';
import RestaurantDetailScreen from './src/pages/RestaurantDetail/RestaurantDetailScreen';
import CartScreen from './src/pages/Cart/CartScreen';
import OrderPreparing from './src/pages/OrderPreparing';
import DeliveryScreen from './src/pages/Delivery/DeliveryScreen';
import Welcome from './src/pages/Welcome';
import LoginScreen from './src/pages/Auth/LoginScreen';
import RegisterScreen from './src/pages/Auth/RegisterScreen';
import {useDispatch, useSelector} from 'react-redux';
import {Init} from './src/redux/User/UserActions';
import {createBottomTabNavigator} from '@react-navigation/bottom-tabs';
import ProfileScreen from './src/pages/Profile/ProfileScreen';
import SearchScreen from './src/pages/Search/SearchScreen';
import {Home, Search, Archive, User, Tag} from 'react-native-feather';
import OrderScreen from './src/pages/Order/OrderScreen';
import Icon, {Icons} from './src/components/Icons';
const Stack = createNativeStackNavigator();
const HomeNav = createNativeStackNavigator();
const Profile = createNativeStackNavigator();
const Tab = createBottomTabNavigator();
const TabArr = [
{
route: 'Home',
type: Icons.Feather,
icon: Home,
label: 'Home',
component: HomeScreen,
},
{
route: 'Search',
type: Icons.Feather,
icon: Search,
label: 'Search',
component: SearchScreen,
},
{
route: 'Order',
type: Icons.Feather,
icon: Archive,
label: 'Order',
component: OrderScreen,
},
{
route: 'Profile',
type: Icons.Feather,
icon: User,
label: 'Profile',
component: ProfileScreen,
},
];
function AuthStack() {
return (
<Stack.Navigator
screenOptions={{
headerShown: false,
statusBarStyle: 'dark',
statusBarColor: 'transparent',
}}>
<Stack.Screen
options={{statusBarTranslucent: true}}
name="LoginScreen"
component={LoginScreen}
/>
<Stack.Screen
options={{statusBarTranslucent: true}}
name="RegisterScreen"
component={RegisterScreen}
/>
</Stack.Navigator>
);
}
function WelcomeStack() {
return (
<Stack.Navigator
screenOptions={{
headerShown: false,
statusBarStyle: 'dark',
statusBarColor: 'transparent',
}}>
<Stack.Screen
options={{statusBarTranslucent: true}}
name="Welcome"
component={Welcome}
/>
</Stack.Navigator>
);
}
function HomeTab() {
return (
<Tab.Navigator
screenOptions={{
headerShown: false,
tabBarShowLabel: false,
tabBarStyle: {
height: 90,
},
}}>
{TabArr.map((item, index) => {
return (
<Tab.Screen
key={index}
name={item.route}
component={item.component}
options={{
tabBarIcon: ({focused}) => (
<View
style={{
borderRadius: 10,
padding: 12,
elevation: focused ? 3 : null,
shadowColor: '#000',
backgroundColor: focused ? COLORS.primary : null,
}}>
<Icon
type={item.icon}
name={item.icon}
color={focused ? COLORS.white : COLORS.gray}
size={2}
/>
</View>
),
}}
/>
);
})}
</Tab.Navigator>
);
}
function HomeStackScreen() {
return (
<HomeNav.Navigator
screenOptions={{
headerShown: false,
statusBarStyle: 'dark',
statusBarColor: 'transparent',
}}>
<HomeNav.Screen
options={{statusBarTranslucent: true}}
name="HomeScreen"
component={HomeTab}
/>
<HomeNav.Screen
options={{statusBarTranslucent: true}}
name="RestaurantDetailScreen"
component={RestaurantDetailScreen}
/>
<HomeNav.Screen
options={{
statusBarTranslucent: true,
}}
name="Cart"
component={CartScreen}
/>
<HomeNav.Screen
options={{
presentation: 'fullScreenModal',
statusBarTranslucent: true,
}}
name="OrderPreparing"
component={OrderPreparing}
/>
<HomeNav.Screen
options={{
presentation: 'fullScreenModal',
statusBarTranslucent: true,
}}
name="DeliveryScreen"
component={DeliveryScreen}
/>
</HomeNav.Navigator>
);
}
function RootNavigation() {
const [isReady, setIsReady] = useState(true);
const token = useSelector(state => state.UserReducers.authToken);
const user = useSelector(state => state.UserReducers.user);
const dispatch = useDispatch();
const init = async () => {
await dispatch(Init());
setTimeout(() => {
setIsReady(false);
}, 1000);
};
useEffect(() => {
init();
});
return (
<NavigationContainer>
{isReady === true ? (
<WelcomeStack />
) : token === null ? (
<AuthStack />
) : (
<HomeStackScreen />
)}
</NavigationContainer>
);
}
export default function Navigation() {
return <RootNavigation />;
}