-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
112 lines (96 loc) · 3.01 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
import 'react-native-gesture-handler';
import React, {useState, useEffect} from 'react';
import {View, StyleSheet, Pressable, SafeAreaView, ActivityIndicator} from 'react-native';
import FontAwesome5 from 'react-native-vector-icons/FontAwesome5';
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
import Ionicons from 'react-native-vector-icons/Ionicons';
import FontAwesome from 'react-native-vector-icons/FontAwesome';
import Amplify, {DataStore, Hub} from 'aws-amplify';
import {withAuthenticator} from 'aws-amplify-react-native';
import config from './src/aws-exports';
import HomeScreen from './src/screens/HomeScreen';
import MatchesScreen from './src/screens/MatchesScreen';
import ProfileScreen from './src/screens/ProfileScreen';
Amplify.configure({
...config,
Analytics: {
disabled: true,
},
});
const App = () => {
const [activeScreen, setActiveScreen] = useState('HOME');
const [isUserLoading, setIsUserLoading] = useState(true);
const color = '#b5b5b5';
const activeColor = '#F76C6B';
useEffect(() => {
const listener = Hub.listen('datastore', async hubData => {
const {event, data} = hubData.payload;
if (event === 'modelSynced' && data?.model?.name === 'User') {
console.log('User Model has finished syncing');
setIsUserLoading(false);
}
});
return () => listener();
}, []);
const renderPage = () => {
if (activeScreen === 'HOME') {
return <HomeScreen isUserLoading={isUserLoading} />;
}
if (isUserLoading) {
return <ActivityIndicator style={{flex: 1}} />;
}
if (activeScreen === 'CHAT') {
return <MatchesScreen />;
}
if (activeScreen === 'PROFILE') {
return <ProfileScreen />;
}
};
return (
<SafeAreaView style={styles.root}>
<View style={styles.pageContainer}>
<View style={styles.topNavigation}>
<Pressable onPress={() => setActiveScreen('HOME')}>
<FontAwesome5
name="user-friends"
size={30}
color={activeScreen === 'HOME' ? activeColor : color}
/>
</Pressable>
<Pressable onPress={() => setActiveScreen('CHAT')}>
<Ionicons
name="ios-chatbubbles"
size={30}
color={activeScreen === 'CHAT' ? activeColor : color}
/>
</Pressable>
<Pressable onPress={() => setActiveScreen('PROFILE')}>
<FontAwesome
name="user"
size={30}
color={activeScreen === 'PROFILE' ? activeColor : color}
/>
</Pressable>
</View>
{renderPage()}
</View>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
root: {
flex: 1,
},
pageContainer: {
justifyContent: 'center',
alignItems: 'center',
flex: 1,
},
topNavigation: {
flexDirection: 'row',
justifyContent: 'space-around',
width: '100%',
padding: 10,
},
});
export default withAuthenticator(App);