/
App.js
415 lines (382 loc) · 13.8 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
// This is the starting point file for the mobile application.
import React, {
useEffect,
useLayoutEffect,
useRef,
useState,
} from 'react';
import {
StyleSheet,
Text,
View,
SafeAreaView,
// Linking,
} from 'react-native';
import * as Linking from 'expo-linking';
import * as Notifications from 'expo-notifications';
import * as Device from 'expo-device';
import {
Alert,
Avatar,
Button,
Icon,
Image,
Input,
Tooltip,
} from 'react-native-elements';
import { MenuProvider } from 'react-native-popup-menu';
import 'react-native-gesture-handler';
import {
NavigationContainer,
useIsFocused
} from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { SafeAreaProvider, useSafeAreaInsets } from 'react-native-safe-area-context';
// ----------------- Temporary visual space for Front-End component testing.
// import FrontEndTestSpace from './screens/deprecated/FrontEndTestSpace';
// Screen imports.
// ----------------- 'AUTHENTICATION' Screens
import UserAuth from './screens/0_Authentication/UserAuth';
import RegisterPhone from './screens/0_Authentication/RegisterPhone';
import Login from './screens/0_Authentication/Login';
import VerifyPhone from './screens/0_Authentication/VerifyPhone';
import PhoneSuccess from './screens/0_Authentication/PhoneSuccess';
import UserCreated from './screens/0_Authentication/UserCreated';
// ----------------- 'HOME' Screens
import HomeTab from './screens/1_Home/HomeTab';
import ActiveEvents from './screens/1_Home/ActiveEvents';
import ViewEventHome from './screens/1_Home/ViewEventHome';
import ActivePolls from './screens/1_Home/ActivePolls';
import ViewPollHome from './screens/1_Home/ViewPollHome';
// ----------------- 'GROUP CHATS' Screens
import GroupChatsTab from './screens/2_GroupChats/GroupChatsTab';
import AddChatScreen from './screens/2_GroupChats/AddChatScreen';
import ChatScreen from './screens/2_GroupChats/ChatScreen';
import FamilyChatScreen from './screens/2_GroupChats/FamilyChatScreen';
import GroupsTab from './screens/2_GroupChats/GroupsTab';
import CreateGroup_1_NameImage from './screens/2_GroupChats/CreateGroup_1_NameImage';
import CreateGroup_2_Members from './screens/2_GroupChats/CreateGroup_2_Members';
import Topics from './screens/2_GroupChats/Topics';
import CreateTopic from './screens/2_GroupChats/CreateTopic';
import AddPin from './screens/2_GroupChats/AddPin';
import Pins from './screens/2_GroupChats/Pins';
import ViewPin from './screens/2_GroupChats/ViewPin';
import AddBanner from './screens/2_GroupChats/AddBanner';
import Banners from './screens/2_GroupChats/Banners';
import ViewBanner from './screens/2_GroupChats/ViewBanner';
import Events from './screens/2_GroupChats/Events';
import AddEvent from './screens/2_GroupChats/AddEvent';
import ViewEvent from './screens/2_GroupChats/ViewEvent';
import Polls from './screens/2_GroupChats/Polls';
import AddPoll from './screens/2_GroupChats/AddPoll';
import ViewPoll from './screens/2_GroupChats/ViewPoll';
import Images from './screens/2_GroupChats/Images';
import ViewImage from './screens/2_GroupChats/ViewImage';
import GroupInvite from './screens/2_GroupChats/GroupInvite';
import GroupMembers from './screens/2_GroupChats/GroupMembers';
import GroupSettings from './screens/2_GroupChats/GroupSettings';
import TopicInvite from './screens/2_GroupChats/TopicInvite';
import TopicMembers from './screens/2_GroupChats/TopicMembers';
import TopicSettings from './screens/2_GroupChats/TopicSettings';
// ----------------- 'DMs' Screens
import DMsTab from './screens/3_DMs/DMsTab';
// ----------------- 'Profile' Screens
import ProfileTab from './screens/4_Profile/ProfileTab';
// ----------------- 'Supplementary' Functions
import GenerateProfileIcon from './screens/5_Supplementary/GenerateProfileIcon';
// Default values for 'navigation.setOptions'.
const globalScreenOptions = {
headerStyle: { backgroundColor: '#2C6BED' },
headerTitleStyle: { color: 'white' },
headerBackTitleStyle: { color: 'white' },
headerTintStyle: 'white'
}
// Imports for: Expo
import { StatusBar } from 'expo-status-bar';
import ImagePicker from 'expo-image-picker';
import { FirebaseRecaptchaVerifierModal } from 'expo-firebase-recaptcha';
// Imports for: Firebase
import {
app,
auth,
db,
firebaseConfig
} from './firebase';
import firebase from 'firebase/compat/app';
import { Tab } from 'react-native-elements/dist/tab/Tab';
import { Timestamp } from 'firebase/firestore';
const Stack = createStackNavigator();
const TabStack = createBottomTabNavigator();
const getInsets = () => {
return useSafeAreaInsets();
}
const TabStackScreen = () => (
<TabStack.Navigator
headerMode="none"
screenOptions={({ route }) => ({
initialRouteName: "Home",
headerShown: false,
tabBarStyle: { height: (80 + getInsets().bottom) },
backgroundColor: 'red',
tabBarLabelStyle: {
fontSize: 15,
paddingBottom: 8,
},
tabBarIcon: ({ color, type, size }) => {
let iconName;
if (route.name === 'Home') {
iconName = 'home';
type = 'material-community';
size = 35;
} else if (route.name === 'Groups') {
iconName = 'group';
type = 'material';
size = 35;
} else if (route.name === 'Messages') {
iconName = 'direction';
type = 'entypo';
size = 28;
} else if (route.name === 'Profile') {
iconName = 'person-pin';
type = 'material';
size = 35;
}
return (
<Icon
name={iconName}
type={type}
size={size}
color={color}
style={{ paddingTop: 8 }}
/>
);
},
tabBarActiveTintColor: "#1174EC",
tabBarInactiveTintColor: '#808080',
})}
>
<TabStack.Screen
name='Home'
component={HomeStackScreen}
screenOptions={{gestureEnabled: false}}
/>
<TabStack.Screen
name='Groups'
component={GroupChatsStackScreen}
/>
<TabStack.Screen
name='Messages'
component={DMsStackScreen}
/>
<TabStack.Screen
name='Profile'
component={ProfileStackScreen}
options={{
tabBarLabel: 'Profile',
tabBarIcon: () => <GenerateProfileIcon />
}}
/>
</TabStack.Navigator>
);
const HomeStackScreen = () => (
<Stack.Navigator screenOptions={{
headerBackTitleVisible: false,
headerTintColor: "#000",
headerTitleAlign: 'center',
}}>
<Stack.Screen name='HomeTab' component={HomeTab} />
<Stack.Screen name='ActiveEvents' component={ActiveEvents} />
<Stack.Screen name='ViewEventHome' component={ViewEventHome} />
<Stack.Screen name='ActivePolls' component={ActivePolls} />
<Stack.Screen name='ViewPollHome' component={ViewPollHome} />
</Stack.Navigator>
)
const GroupChatsStackScreen = () => (
<Stack.Navigator screenOptions={{
headerBackTitleVisible: false,
headerTintColor: "#000",
headerTitleAlign: 'center',
}}>
<Stack.Screen name='GroupsTab' component={GroupsTab} />
<Stack.Screen name='AddChat' component={AddChatScreen} />
<Stack.Screen name='Chat' component={ChatScreen} />
<Stack.Screen name='Topics' component={Topics} />
<Stack.Screen name='CreateGroup_1_NameImage' component={CreateGroup_1_NameImage} />
<Stack.Screen name='CreateGroup_2_Members' component={CreateGroup_2_Members} />
<Stack.Screen name='CreateTopic' component={CreateTopic} />
<Stack.Screen name='AddPin' component={AddPin} />
<Stack.Screen name='Pins' component={Pins} />
<Stack.Screen name='ViewPin' component={ViewPin} />
<Stack.Screen name='AddBanner' component={AddBanner} />
<Stack.Screen name='Banners' component={Banners} />
<Stack.Screen name='ViewBanner' component={ViewBanner} />
<Stack.Screen name='Events' component={Events} />
<Stack.Screen name='AddEvent' component={AddEvent} />
<Stack.Screen name='ViewEvent' component={ViewEvent} />
<Stack.Screen name='Polls' component={Polls} />
<Stack.Screen name='AddPoll' component={AddPoll} />
<Stack.Screen name='ViewPoll' component={ViewPoll} />
<Stack.Screen name='Images' component={Images} />
<Stack.Screen name='ViewImage' component={ViewImage} />
<Stack.Screen name='GroupInvite' component={GroupInvite} />
<Stack.Screen name='GroupMembers' component={GroupMembers} />
<Stack.Screen name='GroupSettings' component={GroupSettings} />
<Stack.Screen name='TopicInvite' component={TopicInvite} />
<Stack.Screen name='TopicMembers' component={TopicMembers} />
<Stack.Screen name='TopicSettings' component={TopicSettings} />
<Stack.Screen name='FamilyChatScreen' component={FamilyChatScreen} />
</Stack.Navigator>
)
const DMsStackScreen = () => (
<Stack.Navigator screenOptions={{
headerBackTitleVisible: false,
headerTintColor: "#000",
headerTitleAlign: 'center',
}}>
<Stack.Screen name='DMsTab' component={DMsTab} />
<Stack.Screen name='Chat' component={ChatScreen} />
</Stack.Navigator>
)
const ProfileStackScreen = () => (
<Stack.Navigator screenOptions={{
headerBackTitleVisible: false,
headerTintColor: "#000",
headerTitleAlign: 'center',
}}>
<Stack.Screen name='ProfileTab' component={ProfileTab} />
</Stack.Navigator>
)
Notifications.setNotificationHandler({
handleNotification: async (notification) => {
const currentRouteName = navRef.current.getCurrentRoute().name;
// console.log("navRef.current.getCurrentRoute() = "+JSON.stringify(navRef.current.getCurrentRoute()))
// console.log("notification = "+JSON.stringify(notification))
const notificationTitle = notification.request.content.title;
const topic = notificationTitle.substring(notificationTitle.indexOf("\"")+1, notificationTitle.length-1);
const name = notificationTitle.substring(0, notificationTitle.indexOf("sent")-1);
// console.log("topic = ."+topic+".")
// console.log("name = ."+name+".")
//show if outside of chat, or topic param doesn't exist or if in a different topic
//show if it's a DM message and first/last name in notification is different than name in dm
if(currentRouteName != "Chat"
|| navRef.current.getCurrentRoute().params == undefined
|| navRef.current.getCurrentRoute().params.topicName == undefined
|| navRef.current.getCurrentRoute().params.topicName != topic
|| (
topic == "DMs"
&& navRef.current.getCurrentRoute().params != undefined
&& navRef.current.getCurrentRoute().params.topicName != undefined
&& name != navRef.current.getCurrentRoute().params.otherUserFullName
)){
return {
shouldShowAlert: true,
shouldPlaySound: false,
shouldSetBadge: false,
}
}
else {
return null;
}
},
});
const prefix = Linking.createURL('/');
// familychat://
// exp://10.186.150.80:19000/--/
// chat/topicId/topicName/groupId/groupName/groupOwner/color/coverImageNumber/lastReadTimeSeconds
const config = {
screens: {
TabStack: {
initialRouteName: "HomeTab",
screens: {
Home: {
initialRouteName: "HomeTab",
screens: {
HomeTab: {path: 'home', exact: true},
},
},
Groups: {
initialRouteName: "GroupsTab",
screens: {
GroupsTab: "GroupsTab",
Chat: {exact: true,
path: 'chat/:topicId/:topicName/:groupId/:groupName/:groupOwner/:color/:coverImageNumber/:lastReadTimeSeconds',
parse: {
lastReadTimeSeconds: seconds => {new Timestamp(seconds, 0)}
}
},
Banners: 'banners',
Events: 'events',
Polls: 'polls',
},
},
Messages: {
screens: {
DMsTab: {
exact: true,
path: 'dms'
},
},
},
Profile: {
screens: {
ProfileTab: 'profile',
},
},
},
},
},
};
const linking = {
prefixes: [prefix],
config: config,
};
export const navRef = React.createRef();
// Screen definitions for the application.
export default function App() {
React.useEffect(() => {
const subscription = Notifications.addNotificationResponseReceivedListener(response => {
console.log("data = "+JSON.stringify(response.notification.request.content.data))
const url = response.notification.request.content.data.url;
Linking.openURL(url);
});
return () => subscription.remove();
}, []);
return (
<SafeAreaProvider>
<MenuProvider customStyles={{
backdrop: {
opacity: 0.35, backgroundColor: "#000"
},
}}>
{/* <SafeAreaView style={styles.safeAreaContainer}> */}
<NavigationContainer linking={linking} ref={navRef}>
{/* <Stack.Navigator screenOptions={globalScreenOptions} > */}
<Stack.Navigator>
{/* Authentication Screens */}
<Stack.Screen name='UserAuth' component={UserAuth} options={{ headerShown: false }} />
<Stack.Screen name='RegisterPhone' component={RegisterPhone} />
<Stack.Screen name='Login' component={Login} />
<Stack.Screen name='VerifyPhone' component={VerifyPhone} />
<Stack.Screen name="PhoneSuccess" component={PhoneSuccess} />
<Stack.Screen name="UserCreated" component={UserCreated} />
{/* Tabbed Screens */}
<Stack.Screen name="TabStack" component={TabStackScreen} options={{ headerShown: false }} />
</Stack.Navigator>
</NavigationContainer>
{/* </SafeAreaView> */}
</MenuProvider>
</SafeAreaProvider>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
safeAreaContainer: {
flex: 1,
},
});