-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
164 lines (156 loc) · 5.12 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
import React, { useEffect, useState, useContext } from "react";
import RNBootSplash from "react-native-bootsplash";
import { StatusBar } from "react-native";
import LoadingOverlay from "./UI/LoadingOverlay";
import Welcome from "./screens/Welcome";
import SignIn from "./screens/auth/SignIn";
import SignUp from "./screens/auth/SignUp";
import store from "./store/redux/store";
import AuthContentProvider from "./store/checkAuth";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { AuthContext } from "./store/checkAuth";
import { Provider, useDispatch } from "react-redux";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { NavigationContainer } from "@react-navigation/native";
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import {
ChatScreenNavigator,
HomeScreenNavigator,
OrderScreenNavigator,
ProfileScreenNavigator,
} from "./CustomNavigation";
import { ColorPalate, MyFonts } from "./constants/var";
import MaterialIcons from "react-native-vector-icons/MaterialIcons";
import FontAwsomeIcon from "react-native-vector-icons/FontAwesome";
import LoginAsGuest from "./screens/auth/LoginAsGuest";
import EnterEmail from "./screens/auth/EnterEmail";
import OTPVarificationScreen from "./screens/auth/OTPVarificationScreen";
import ForgotPasswordScreen from "./screens/auth/ForgotPasswordScreen";
import FlashMessage from "react-native-flash-message";
import ChatScreen from "./screens/chat/ChatScreen";
const Stack = createNativeStackNavigator();
const Bottom = createBottomTabNavigator();
function AuthStack() {
return (
<Stack.Navigator screenOptions={{ headerShown: false }}>
<Stack.Screen name="Welcome" component={Welcome} />
<Stack.Screen name="SignIn" component={SignIn} />
<Stack.Screen name="SignUp" component={SignUp} />
<Stack.Screen name="Email" component={EnterEmail} />
<Stack.Screen name="OTPVarify" component={OTPVarificationScreen} />
<Stack.Screen name="ForgotPassword" component={ForgotPasswordScreen} />
<Stack.Screen name="Guest" component={LoginAsGuest} />
</Stack.Navigator>
);
}
function AuthenticatedStack() {
return (
<Bottom.Navigator
screenOptions={{
tabBarActiveTintColor: ColorPalate.themeprimary,
headerShown: false,
}}
>
<Bottom.Screen
name="HomeScreen"
component={HomeScreenNavigator}
options={{
title: "Modern Laundry",
tabBarLabel: "Home",
tabBarLabelStyle: { fontFamily: MyFonts.fontregular },
tabBarIcon: ({ color, size }) => (
<MaterialIcons name="home" color={color} size={26} />
),
}}
/>
<Bottom.Screen
name="OrdersScreen"
component={OrderScreenNavigator}
options={{
tabBarLabel: "Orders",
tabBarLabelStyle: { fontFamily: MyFonts.fontregular },
tabBarIcon: ({ color, size }) => (
<MaterialIcons name="list-alt" color={color} size={26} />
),
}}
/>
<Bottom.Screen
name="ChatScreen"
// component={ChatScreen}
component={ChatScreenNavigator}
options={{
tabBarLabel: "Chat",
tabBarLabelStyle: { fontFamily: MyFonts.fontregular },
tabBarIcon: ({ color, size }) => (
<MaterialIcons name="chat" color={color} size={26} />
),
}}
/>
<Bottom.Screen
name="ProfileScreen"
component={ProfileScreenNavigator}
options={{
tabBarLabel: "Account",
tabBarLabelStyle: { fontFamily: MyFonts.fontregular },
tabBarIcon: ({ color, size }) => (
<FontAwsomeIcon name="user" color={color} size={26} />
),
}}
/>
</Bottom.Navigator>
);
}
function Navigation() {
const authCntx = useContext(AuthContext);
return (
<NavigationContainer>
{!authCntx.isAuthendicate && <AuthStack />}
{authCntx.isAuthendicate && <AuthenticatedStack />}
</NavigationContainer>
);
}
function TokenCheck() {
const [isTryingToLogging, setisTryingToLogging] = useState(true);
const authCntx = useContext(AuthContext);
useEffect(() => {
const checkStoredToken = async () => {
try {
const storedToken = await AsyncStorage.getItem("customerId");
storedToken && authCntx.authenticate(storedToken);
setisTryingToLogging(false);
} catch (error) {
console.log(error);
}
};
checkStoredToken();
}, []);
if (isTryingToLogging) {
return <LoadingOverlay message="wait a moment" />;
}
return <Navigation />;
}
const App = () => {
useEffect(() => {
RNBootSplash.hide();
}, []);
return (
<>
<Provider store={store}>
<AuthContentProvider>
<StatusBar style="light" />
<TokenCheck />
<FlashMessage
position="top"
textStyle={{
fontFamily: MyFonts.fontregular,
}}
titleStyle={{
fontFamily: MyFonts.fontregular,
}}
/>
</AuthContentProvider>
</Provider>
</>
);
};
export default App;