-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
143 lines (134 loc) · 3.92 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
import React, { useState, useEffect } from "react";
import { LogBox, Text } from "react-native";
import { useAssets } from "expo-asset";
import { onAuthStateChanged } from "firebase/auth";
import { auth } from "./firebase";
import { NavigationContainer } from "@react-navigation/native";
import { createStackNavigator } from "@react-navigation/stack";
import { createMaterialTopTabNavigator } from "@react-navigation/material-top-tabs";
import SignIn from "./screens/SignIn";
import ContextWrapper from "./context/ContextWrapper";
import Profile from "./screens/Profile";
import Photo from "./screens/Photo";
import Chats from "./screens/Chats";
import { Ionicons } from "@expo/vector-icons";
import Contacts from "./screens/Contacts";
import ChatHeader from "./components/ChatHeader";
import Chat from "./screens/Chat";
LogBox.ignoreLogs([
"Setting a timer",
"AsyncStorage has been extracted from react-native core and will be removed in a future release.",
]);
const Stack = createStackNavigator();
const Tab = createMaterialTopTabNavigator();
function App() {
const [currUser, setCurrUser] = useState(null);
const [loading, setLoading] = useState(true);
useEffect(() => {
const unsubscribe = onAuthStateChanged(auth, (user) => {
setLoading(false);
if (user) {
setCurrUser(user);
}
});
return () => unsubscribe();
}, []);
if (loading) {
return <Text>Loading...</Text>;
}
return (
<NavigationContainer className="w-[100%] h-[100%] flex justify-center items-center">
{!currUser ? (
<Stack.Navigator screenOptions={{ headerShown: false }}>
<Stack.Screen name="signIn" component={SignIn} />
</Stack.Navigator>
) : (
<Stack.Navigator
screenOptions={{
headerStyle: {
backgroundColor: "#0056b3",
shadowOpacity: 0,
elevation: 0,
},
headerTintColor: "#ffffff",
}}
>
{!currUser.displayName && (
<Stack.Screen
name="profile"
component={Profile}
options={{ headerShown: false }}
/>
)}
<Stack.Screen
name="home"
component={Home}
options={{ title: "Chat Up" }}
/>
<Stack.Screen
name="contacts"
component={Contacts}
options={{ title: "Select Contacts" }}
/>
<Stack.Screen
name="chat"
component={Chat}
options={{ headerTitle: (props) => <ChatHeader {...props} /> }}
/>
</Stack.Navigator>
)}
</NavigationContainer>
);
}
function Home() {
return (
<Tab.Navigator
screenOptions={({ route }) => {
return {
tabBarLabel: () => {
if (route.name === "photo") {
return <Ionicons name="camera" size={20} color="#ffffff" />;
} else {
return (
<Text className="text-[#ffffff]">
{route.name.toLocaleUpperCase()}
</Text>
);
}
},
tabBarShowIcon: true,
tabBarLabelStyle: {
color: "#ffffff",
},
tabBarIndicatorStyle: {
backgroundColor: "#ffffff",
},
tabBarStyle: {
backgroundColor: "#0056b3",
},
};
}}
initialRouteName="chats"
>
<Tab.Screen name="photo" component={Photo}></Tab.Screen>
<Tab.Screen name="chats" component={Chats}></Tab.Screen>
</Tab.Navigator>
);
}
function Main() {
const [assets] = useAssets(
require("./assets/icon-square.png"),
require("./assets/chatbg.png"),
require("./assets/user-icon.png"),
require("./assets/welcome-img.png")
);
if (!assets) {
return <Text>Loading...</Text>;
}
return (
<ContextWrapper>
<App />
</ContextWrapper>
);
}
export default Main;