-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathApp.js
98 lines (91 loc) · 2.93 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
import "@expo/metro-runtime";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { StatusBar } from "expo-status-bar";
import { useEffect, useState } from "react";
import { ActivityIndicator } from "react-native";
import AccountScreen from "./src/screens/AccountScreen";
import EmbeddedFormScreen from "./src/screens/EmbeddedFormScreen";
import EndScreen from "./src/screens/EndScreen";
import HomeScreen from "./src/screens/HomeScreen";
import SignInScreen from "./src/screens/SignInScreen";
import VolunteerFormScreen from "./src/screens/VolunteerFormScreen";
import VolunteerOpportunityScreen from "./src/screens/VolunteerOpportunityScreen";
import HomeHeader from "./src/components/HomeHeader";
import colors from "./src/constants/colors";
import { alertError } from "./src/utils";
const Stack = createNativeStackNavigator();
export default function App() {
const [loading, setLoading] = useState(true);
const [isLoggedIn, setIsLoggedIn] = useState(false);
useEffect(() => {
(async () => {
try {
const userString = await AsyncStorage.getItem("user");
setIsLoggedIn(userString != null);
} catch (error) {
alertError(`While getting user in App: ${error}`);
} finally {
setLoading(false);
}
})();
}, []);
if (loading) {
return <ActivityIndicator size="large" />;
}
return (
<NavigationContainer>
<StatusBar style="light" />
<Stack.Navigator
initialRouteName={isLoggedIn ? "Home" : "Sign In"}
screenOptions={{
headerStyle: {
backgroundColor: colors.primary,
},
headerTintColor: colors.white,
}}
>
<Stack.Screen
name="Sign In"
component={SignInScreen}
options={{
headerBackVisible: false,
}}
/>
<Stack.Screen
name="Home"
component={HomeScreen}
options={{
header: (props) => <HomeHeader {...props} />,
}}
/>
<Stack.Screen
name="Account"
component={AccountScreen}
options={{ animation: "slide_from_bottom" }}
/>
<Stack.Screen
name="Volunteer Opportunity"
component={VolunteerOpportunityScreen}
options={{
title: null,
headerStyle: {
backgroundColor: colors.black,
},
}}
/>
<Stack.Screen name="Sign Up Form" component={VolunteerFormScreen} />
<Stack.Screen name="Google Forms" component={EmbeddedFormScreen} />
<Stack.Screen
name="End"
component={EndScreen}
options={{
title: null,
headerBackVisible: false,
}}
/>
</Stack.Navigator>
</NavigationContainer>
);
}