-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
171 lines (147 loc) · 4.64 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
import { useContext, useEffect, useState } from "react";
import { SafeAreaView } from "react-native";
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { StatusBar } from "expo-status-bar";
import AsyncStorage from "@react-native-async-storage/async-storage";
import LoadingScreen from "./constants/LoadingScreen";
import ResetScreen from "./screens/ResetScreen";
import LoginScreen from "./screens/LoginScreen";
import SignupScreen from "./screens/SignupScreen";
import WelcomeScreen from "./screens/WelcomeScreen";
import { Colors } from "./constants/styles";
import AuthContextProvider, { AuthContext } from "./store/auth-context";
import IconButton from "./components/ui/IconButton";
import CustomHeader from "./constants/customheader";
import CustomHeader1 from "./constants/CustomHeader1";
import EmailVerificationScreen from "./screens/EmailVerification";
import handleEmailAuth from "./screens/SigninTypes";
import Otp from "./screens/OtpVerification";
import { useNavigation } from "@react-navigation/native";
const Stack = createNativeStackNavigator();
function AuthStack() {
return (
<SafeAreaView style={{ flex: 1 }}>
<Stack.Navigator
screenOptions={{
headerStyle: { backgroundColor: Colors.primary500 },
headerTintColor: "white",
cardStyle: { backgroundColor: Colors.primary100 }, // Use 'cardStyle' for the content background
}}
>
<Stack.Screen
name="signintypes"
component={handleEmailAuth}
options={{ headerShown: false }}
/>
<Stack.Screen
name="PhoneAuthentication"
component={Otp}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Login"
component={LoginScreen}
options={{ header: () => <CustomHeader /> }}
/>
<Stack.Screen
name="Signup"
component={SignupScreen}
options={{ headerShown: false }}
/>
<Stack.Screen
name="EmailVerification"
component={EmailVerificationScreen}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Reset"
component={ResetScreen}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Welcomes"
component={WelcomeScreen}
options={{ header: () => <CustomHeader1 /> }}
/>
</Stack.Navigator>
</SafeAreaView>
);
}
console.log(LoginScreen);
function AuthenticatedStack() {
const authCtx = useContext(AuthContext);
return (
<SafeAreaView style={{ flex: 1 }}>
<Stack.Navigator
screenOptions={{
headerStyle: { backgroundColor: Colors.primary500 },
headerTintColor: "white",
contentStyle: { backgroundColor: Colors.primary100 },
}}
>
<Stack.Screen
name="Welcomes"
component={WelcomeScreen}
// options={{ header: () => <CustomHeader1 /> }}
options={{
headerRight: ({ tintColor }) => (
<IconButton
icon="exit"
color={tintColor}
size={24}
onPress={authCtx.logout}
/>
),
}}
/>
</Stack.Navigator>
</SafeAreaView>
);
}
function Navigation() {
const authCtx = useContext(AuthContext);
return (
<NavigationContainer>
{!authCtx.isAuthenticated && <AuthStack />}
{authCtx.isAuthenticated && <AuthenticatedStack />}
</NavigationContainer>
);
}
const navigation = useNavigation();
function Root() {
const [isLoadingComplete, setIsLoadingComplete] = useState(false);
const authCtx = useContext(AuthContext);
useEffect(() => {
async function loadAppData() {
try {
const storedToken = await AsyncStorage.getItem("token");
if (storedToken) {
authCtx.authenticate(storedToken);
}
// Simulate additional loading (replace with your actual loading logic)
await new Promise((resolve) => setTimeout(resolve, 2000));
setIsLoadingComplete(true);
} catch (error) {
console.error("Error loading app data:", error);
setIsLoadingComplete(true); // In case of an error, still mark loading as complete
}
}
loadAppData();
}, [authCtx]);
if (!isLoadingComplete) {
return <LoadingScreen />;
}
return <Navigation />;
}
export default function App() {
return (
<>
<StatusBar style="light" />
<Proot />
<AuthContextProvider>
<Root />
</AuthContextProvider>
</>
);
}