-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
141 lines (134 loc) · 3.84 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
import { Platform, SafeAreaView, StatusBar, StyleSheet } from "react-native";
import { NavigationContainer } from "@react-navigation/native";
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import { Provider, useDispatch, useSelector } from "react-redux";
import { store } from "./src/redux/store";
import {
HomeNavigator,
LoginNavigator,
MessagesNavigator,
} from "./Navigation";
import { AntDesign } from "@expo/vector-icons";
const Tab = createBottomTabNavigator();
import { Entypo } from "@expo/vector-icons";
import { useEffect, useState } from "react";
import { auth, logoutUser } from "./db/firebaseConfig";
import { onAuthStateChanged } from "@firebase/auth";
import { loginToken } from "./src/redux/actionCreator";
export default function App() {
return (
<Provider store={store}>
<ChildApp />
</Provider>
);
}
function ChildApp() {
const [isAuth, setIsAuth] = useState(null);
const dispatch = useDispatch();
const token = useSelector((state) => state.setAccessToken);
onAuthStateChanged(auth, (user) => {
if (user) {
setIsAuth(user.email);
}
});
useEffect(() => {
dispatch(loginToken(isAuth));
}, [dispatch, isAuth]);
return (
<SafeAreaView style={styles.container}>
<NavigationContainer>
<Tab.Navigator
screenOptions={{
tabBarStyle: styles.tab,
}}
tabBarOptions={{
activeTintColor: "#3796f3",
inactiveTintColor: "grey",
}}
>
<Tab.Screen
name="Home"
options={{
headerShown: false,
tabBarIcon: (tabInfo) => {
return (
<Entypo
name="home"
size={22}
color={tabInfo.focused ? "#3796f3" : "#8e8e93"}
/>
);
},
}}
component={HomeNavigator}
/>
{token ? (
<>
<Tab.Screen
name="Messages"
options={{
headerShown: false,
tabBarIcon: (tabInfo) => {
return (
<Entypo
name="chat"
size={22}
color={tabInfo.focused ? "#3796f3" : "#8e8e93"}
/>
);
},
}}
component={MessagesNavigator}
/>
<Tab.Screen
name="Logout"
options={{
headerShown: false,
tabBarIcon: (tabInfo) => {
return (
<AntDesign
onPress={() => logoutUser()}
name="logout"
size={22}
color={tabInfo.focused ? "#3796f3" : "#8e8e93"}
/>
);
},
}}
component={HomeNavigator}
/>
</>
) : (
<Tab.Screen
name="Login"
options={{
headerShown: false,
tabBarIcon: (tabInfo) => {
return (
<AntDesign
name="login"
size={24}
color={tabInfo.focused ? "#3796f3" : "#8e8e93"}
/>
);
},
}}
component={LoginNavigator}
/>
)}
</Tab.Navigator>
</NavigationContainer>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
paddingTop: Platform.OS === "android" ? StatusBar.currentHeight : 0,
},
tab: {
paddingBottom: 10,
paddingTop: 10,
height: "8%",
},
});