-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
195 lines (180 loc) · 5.63 KB
/
App.js
File metadata and controls
195 lines (180 loc) · 5.63 KB
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import React from "react";
import LoginView from "./LoginView";
import SignupView from "./SignupView";
import TodayView from "./TodayView";
import ExercisesView from "./ExercisesView";
import ProfileView from "./ProfileView";
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import { createStackNavigator } from "@react-navigation/stack";
import { NavigationContainer } from "@react-navigation/native";
import Ionicons from "react-native-vector-icons/Ionicons";
import { FontAwesome5 } from "@expo/vector-icons";
import { MaterialIcons } from "@expo/vector-icons";
import { TouchableOpacity, Image, View, Text } from "react-native";
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
accessToken: undefined,
username: undefined,
};
this.login = this.login.bind(this);
this.revokeAccessToken = this.revokeAccessToken.bind(this);
this.SignoutButton = this.SignoutButton.bind(this);
}
/**
* Store the username and accessToken here so that it can be
* passed down to each corresponding child view.
*/
login(username, accessToken) {
this.setState({
username: username,
accessToken: accessToken,
});
}
/**
* Revokes the access token, effectively signing a user out of their session.
*/
revokeAccessToken() {
this.setState({
accessToken: undefined,
});
}
/**
* Defines a signout button... Your first TODO!
*/
SignoutButton = () => {
return (
<>
<View style={{ flexDirection: "row", marginRight: 25 }}>
<TouchableOpacity onPress={() => this.revokeAccessToken()}>
<Text> Log Out</Text>
</TouchableOpacity>
</View>
</>
);
};
MyTabs = () => {
const Tab = createBottomTabNavigator();
return (
<Tab.Navigator
tabBarOptions={{
activeTintColor: "tomato",
inactiveTintColor: "gray",
}}
>
<Tab.Screen
name="Today"
options={{
tabBarIcon: ({ focused, color, size }) => (
<MaterialIcons name="today" size={24} color="black" />
),
}}
children={(props) => (
<TodayView
{...props}
username={this.state.username}
accessToken={this.state.accessToken}
revokeAccessToken={this.state.revokeAccessToken}
/>
)}
/>
<Tab.Screen
name="Exercises"
accessible={true}
accessibilityLabel="Exercises"
options={{
tabBarIcon: ({ focused, color, size }) => (
<MaterialIcons name="directions-run" size={24} color="black" />
),
}}
children={(props) => (
<ExercisesView
{...props}
username={this.state.username}
accessToken={this.state.accessToken}
revokeAccessToken={this.state.revokeAccessToken}
/>
)}
/>
<Tab.Screen
name="Profile"
accessible={false}
options={{
tabBarIcon: ({ focused, color, size }) => (
<FontAwesome5 name="user" size={24} color="black" />
),
}}
children={(props) => (
<ProfileView
{...props}
username={this.state.username}
accessToken={this.state.accessToken}
revokeAccessToken={this.state.revokeAccessToken}
/>
)}
/>
</Tab.Navigator>
);
};
/**
* Note that there are many ways to do navigation and this is just one!
* I chose this way as it is likely most familiar to us, passing props
* to child components from the parent.
*
* Other options may have included contexts, which store values above
* (similar to this implementation), or route parameters which pass
* values from view to view along the navigation route.
*
* You are by no means bound to this implementation; choose what
* works best for your design!
*/
render() {
// Our primary navigator between the pre and post auth views
// This navigator switches which screens it navigates based on
// the existent of an access token. In the authorized view,
// which right now only consists of the profile, you will likely
// need to specify another set of screens or navigator; e.g. a
// list of tabs for the Today, Exercises, and Profile views.
let AuthStack = createStackNavigator();
//added navigator, for navigating between TodayView, ProfileView, and ExercisesView
return (
<NavigationContainer>
<AuthStack.Navigator>
{!this.state.accessToken ? (
<>
<AuthStack.Screen
name="SignIn"
options={{
title: "Fitness Tracker Welcome",
}}
>
{(props) => <LoginView {...props} login={this.login} />}
</AuthStack.Screen>
<AuthStack.Screen
name="SignUp"
options={{
title: "Fitness Tracker Signup",
}}
>
{(props) => <SignupView {...props} />}
</AuthStack.Screen>
</>
) : (
<>
<AuthStack.Screen
name="FitnessTracker"
options={{
headerLeft: this.SignoutButton,
}}
>
{this.MyTabs}
</AuthStack.Screen>
</>
)}
</AuthStack.Navigator>
</NavigationContainer>
);
}
}
export default App;