-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppOrig.js
143 lines (131 loc) · 4.58 KB
/
AppOrig.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
import React, { useState, useEffect, useContext } from "react";
import { StyleSheet, Text, View } from "react-native";
import * as SplashScreen from "expo-splash-screen";
import { NavigationContainer } from "@react-navigation/native";
import { createStackNavigator } from "@react-navigation/stack";
import { createDrawerNavigator } from "@react-navigation/drawer";
import SignupStepperScreen from "./Screens/SignupStepperScreen";
import HomeScreen from "./Screens/HomeScreen";
import LoginScreen from "./Screens/LoginScreen";
import ResetPasswordScreen from "./Screens/ResetPasswordScreen";
import AddServiceScreen from "./Screens/AddServiceScreen";
import AddVehicleScreen from "./Screens/AddVehicleScreen";
import ServiceScreen from "./Screens/ServiceScreen";
import VehicleScreen from "./Screens/VehicleScreen";
import EditServiceScreen from "./Screens/EditServiceScreen";
import { OwnerProvider } from "./Contexts/OwnerContext";
import { VehicleProvider } from "./Contexts/VehicleContext";
import { ServiceProvider } from "./Contexts/ServiceContext";
import GetToken from "./StaticFiles/GetToken";
import CustomDrawerContent from "./Navigators/CustomDrawerContent";
import MainStackNavigator from "./Navigators/MainStackNavigator";
const App = () => {
const Stack = createStackNavigator();
const Drawer = createDrawerNavigator();
const [appIsReady, setAppIsReady] = useState(false);
const [initialRoute, setInitialRoute] = useState("");
useEffect(() => {
async function holdUntilAppLoads() {
try {
await SplashScreen.preventAutoHideAsync();
} catch (e) {
console.log("Splash screen error");
} finally {
prepareResources();
}
}
holdUntilAppLoads();
}, []);
const prepareResources = async () => {
try {
let token = await GetToken();
if (token === null) {
setInitialRoute("Login");
} else {
setInitialRoute("Home");
}
} catch (e) {
console.warn(e);
} finally {
setAppIsReady(true);
await SplashScreen.hideAsync();
}
};
if (!appIsReady) {
return null;
} else {
return (
<OwnerProvider>
<VehicleProvider>
<ServiceProvider>
<NavigationContainer>
{initialRoute === "Login" ? (
<Stack.Navigator initialRouteName="Login">
<Stack.Screen
options={{ headerShown: false }}
name="SignupStepper"
component={SignupStepperScreen}
/>
<Stack.Screen
options={{ headerShown: false }}
name="Login"
component={LoginScreen}
/>
<Stack.Screen
options={{ headerShown: false }}
name="ResetPassword"
component={ResetPasswordScreen}
/>
<Stack.Screen
options={{ headerShown: false }}
name="Home"
component={HomeScreen}
/>
<Stack.Screen
options={{ headerShown: true }}
name="AddService"
component={AddServiceScreen}
/>
<Stack.Screen
options={{ headerShown: true }}
name="Vehicle"
component={AddVehicleScreen}
/>
</Stack.Navigator>
) : (
<Drawer.Navigator
initialRouteName="Home"
drawerType="slide"
drawerContent={(props) => <CustomDrawerContent {...props} />}
>
<Drawer.Screen name="Home" component={MainStackNavigator} />
<Drawer.Screen
options={{ headerShown: true }}
name="Service"
component={ServiceScreen}
initialParams={{ reloadUI: false }}
/>
<Drawer.Screen
options={{ headerShown: true }}
name="Vehicle"
component={VehicleScreen}
initialParams={{ reloadUI: false }}
/>
</Drawer.Navigator>
)}
</NavigationContainer>
</ServiceProvider>
</VehicleProvider>
</OwnerProvider>
);
}
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
},
});
export default App;