-
Notifications
You must be signed in to change notification settings - Fork 2
/
App.js
109 lines (97 loc) · 3.47 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
import { StatusBar } from "expo-status-bar";
import * as React from "react";
import { NavigationContainer, StackActions } from "@react-navigation/native";
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { SafeAreaProvider } from "react-native-safe-area-context";
import { FontAwesomeIcon } from "@fortawesome/react-native-fontawesome";
import {
faHome,
faClock,
faCog,
faUser,
} from "@fortawesome/free-solid-svg-icons";
import AsyncStorage from "@react-native-async-storage/async-storage";
import Login from "./app/pages/Login";
import Home from "./app/pages/Home";
import Alarms from "./app/pages/Alarms";
import Profile from "./app/pages/Profile";
import SignUp from "./app/pages/SignUp";
const Tab = createBottomTabNavigator();
export const Stack = createNativeStackNavigator();
export const UserContext = React.createContext({
user: {},
setUser: () => {},
});
export default function App() {
const [user, setUser] = React.useState({
isLoggedIn: false,
user: null,
token: null,
});
const value = React.useMemo(() => ({ user, setUser }), [user]);
React.useEffect(() => {
const user = AsyncStorage.getItem("user");
if (user) {
setUser(user);
}
}, []);
return (
<UserContext.Provider value={value}>
<SafeAreaProvider>
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen
name="Log-In"
component={Login}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Dashboard"
component={Dashboard}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Sign-Up"
component={SignUp}
options={{ headerShown: false }}
/>
</Stack.Navigator>
</NavigationContainer>
<StatusBar style="dark" />
</SafeAreaProvider>
</UserContext.Provider>
);
}
const Dashboard = () => {
return (
<Tab.Navigator
initialRouteName="Login"
screenOptions={({ route }) => ({
tabBarIcon: ({ focused, color, size }) => {
let iconName;
if (route.name === "Home") {
iconName = faHome;
} else if (route.name === "Alarms") {
iconName = faClock;
} else if (route.name === "Profile") {
iconName = faUser;
}
// You can return any component that you like here!
return (
<FontAwesomeIcon
icon={iconName}
size={size}
color={color}
/>
);
},
headerShown: false,
})}
>
<Tab.Screen name="Home" component={Home} />
<Tab.Screen name="Alarms" component={Alarms} />
<Tab.Screen name="Profile" component={Profile} />
</Tab.Navigator>
);
};