-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
190 lines (161 loc) · 6.7 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import React,{useContext, useEffect, useState} from 'react';
//Navigation
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { NavigationContainer } from '@react-navigation/native';
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import {View, StyleSheet, Text, TouchableHighlight, TouchableOpacity} from "react-native";
import { Ionicons } from '@expo/vector-icons';
//Screens
import Login from './screens/LoginScreen';
import Home from './screens/HomeScreen';
import UserHistory from './screens/User/UserHistory';
import UserRegister from './screens/User/UserRegister';
import EstablishmentRegister from './Establishment/EstablishmentRegister';
import PasswordRecovery from './screens/PasswordRecovery';
import UserPerfil from './screens/User/UserPerfil';
import EstablishmentPage from './screens/Establishment/EstablishmentPage';
import ReadQRcode from './screens/ReadQRCode';
//Provider
import "react-native-gesture-handler";
import { AuthProvider } from './context/AuthContext';
import { AuthContext } from './context/AuthContext';
//services
import { loggedUserData, subscribeOnAuthStateChanged, onPressLogout} from './services/firebaseService';
import AsyncStorage from '@react-native-async-storage/async-storage';
const Stack = createNativeStackNavigator();
const Tab = createBottomTabNavigator();
const PerfilStack = () => (
<Stack.Navigator screenOptions={{ cardStyle: {backgroundColor: "#fff"}, headerShown:false}}>
<Stack.Screen name="UserHistory" component={UserHistory}/>
</Stack.Navigator>
);
const EstablishmentStack = () => (
<Stack.Navigator screenOptions={{ cardStyle: {backgroundColor: "#fff"}, headerShown:false}}>
<Stack.Screen name="EstablishmentPage" component={EstablishmentPage}/>
</Stack.Navigator>
);
function App() {
const { authDispatch, authState} = useContext(AuthContext);
const [aux, setAux] = useState(true);
useEffect(()=>{
const unsub = subscribeOnAuthStateChanged((authCredential)=>{
if(authCredential!=null){
loggedUserData(authCredential.uid, (data) => {
authDispatch({ type: "login", payload: data });
});
}else{
authDispatch({type:"logout"});
}
});
return () => unsub();
},[]);
return (
<>
<NavigationContainer>
{
// authState.isAuthenticated ? (
aux ? (
<Tab.Navigator
screenOptions={({ route }) => ({
tabBarShowLabel:false,
headerShown:false,
tabBarStyle: {backgroundColor: '#70cf97',borderTopWidth:2,borderTopColor:"#cdcdcd",height:65,paddingTop:3},
tabBarIcon: ({ focused }) => {
let iconName;
let textIcon;
switch (route.name) {
case "UserPerfil":
iconName = focused ? 'person' : 'person';
textIcon = "Perfil";
break;
case "QrCodePage":
iconName = focused ? 'qr-code-outline' : 'qr-code-outline';
textIcon = "Ler QRcode";
break;
case "Home":
iconName = focused ? 'home' : 'home';
textIcon = "Página Inicial";
break;
}
return (
<View style={{padding:5, justifyContent:"center",alignItems:"center"}}>
{
iconName==="qr-code-outline" ? (
<View style={{backgroundColor:"white", borderRadius:50,borderColor:"#cdcdcd", borderWidth:2, padding:5, height:80, justifyContent:"center", alignItems:"center"}}>
<Ionicons name={iconName} size={25} color="black" style={{alignSelf:"center"}}></Ionicons>
<Text style={{color:"black",fontWeight:"500", fontSize:13, paddingBottom:3}}>{textIcon}</Text>
</View>
):(
<>
<Ionicons name={iconName} size={25} color={focused ? "white" : "black"}></Ionicons>
<Text style={{color:focused ? "white":"black",fontWeight:"500", fontSize:13, paddingBottom:3}}>{textIcon}</Text>
</>
)
}
</View>
)
},
})}>
<Tab.Screen name="Home" component={Home}
options={{
headerStyle:{
backgroundColor:"#fff"
}
}}/>
<Tab.Screen name="QrCodePage" component={ReadQRcode}
options={{
headerStyle:{
backgroundColor:"#fff"
}
}}/>
<Tab.Screen name="UserPerfil" component={UserPerfil}
options={{
headerStyle:{
backgroundColor:"#fff",
},
title:"Perfil",
}}/>
<Tab.Screen name="PerfilStack" component={PerfilStack} options={{ tabBarButton: () => null, tabBarVisible: false}}/>
<Tab.Screen name="EstablishmentStack" component={EstablishmentStack} options={{ tabBarButton: () => null, tabBarVisible: false}}/>
</Tab.Navigator>
) : (
<Stack.Navigator>
<Stack.Screen name="Login" component={Login} options={{
headerShown:false
}}/>
<Stack.Screen name="EstablishmentRegister" component={EstablishmentRegister} options={{
headerTitle:"Registo de Estabelecimento",
headerStyle:{
backgroundColor:"#F9E9A2",
}
}} />
<Stack.Screen name="UserRegister" component={UserRegister} options={{
headerTitle:"",
headerTransparent:"true",
headerStyle: {
backgroundColor:"#F9E9A2",
}
}} />
<Stack.Screen name="PasswordRecovery" component={PasswordRecovery} options={{
headerTitle:"Recuperar Password",
headerTransparent:"true",
headerStyle: {
backgroundColor:"#F9E9A2",
borderBottomWidth:2,
borderBottomColor:"#6FCF97"
},
}} />
</Stack.Navigator>
)
}
</NavigationContainer>
</>
);
};
export default () => {
return (
<AuthProvider>
<App></App>
</AuthProvider>
);
};