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
|
import {useNavigation} from '@react-navigation/native';
import React, {useMemo} from 'react';
import {
Image,
ScrollView,
StyleSheet,
Text,
TouchableOpacity,
View,
} from 'react-native';
import {ProfilePreview} from '..';
import {MomentTagType, ProfilePreviewType, ScreenType} from '../../types';
import {normalize, SCREEN_HEIGHT} from '../../utils/layouts';
interface TagFriendsFooterProps {
tags: MomentTagType[];
setTags: (tags: MomentTagType[]) => void;
}
const TagFriendsFooter: React.FC<TagFriendsFooterProps> = ({tags, setTags}) => {
const navigation = useNavigation();
const handleRemoveTag = (user: ProfilePreviewType) => {
setTags(tags.filter((tag) => tag.user.id !== user.id));
};
const goToSelectionScreen = () => {
navigation.navigate('TagSelectionScreen', {
selectedTags: tags,
});
};
const taggMoreButton = useMemo(
() => (
<TouchableOpacity
onPress={goToSelectionScreen}
style={styles.tagMoreContainer}>
<Image
source={require('../../assets/icons/tagging/white-plus-icon.png')}
style={styles.tagMoreIcon}
/>
<Text style={styles.tagMoreLabel}>{'Tag More'}</Text>
</TouchableOpacity>
),
[tags],
);
const TaggedUser = (user: ProfilePreviewType) => (
<View style={styles.taggedUserContainer} key={user.id}>
<TouchableOpacity
style={styles.closeIconContainer}
onPress={() => handleRemoveTag(user)}>
<Image
source={require('../../assets/icons/tagging/x-icon.png')}
style={styles.closeIcon}
/>
</TouchableOpacity>
<ProfilePreview
profilePreview={user}
previewType={'Tag Selection'}
screenType={ScreenType.Profile}
/>
</View>
);
/*
* Title/Button depending on the number of users inside taggedUsers list
* If taggUsers is empty, title acts as a button
* Else, gets disabled and TaggMore button appears
*/
const tagFriendsTitle = useMemo(
() => (
<TouchableOpacity
style={styles.tagFriendsTitleContainer}
disabled={tags.length !== 0}
onPress={() =>
navigation.navigate('TagSelectionScreen', {
selectedTags: tags,
})
}>
<Image
source={require('../../assets/icons/tagging/tag-icon.png')}
style={styles.tagIcon}
/>
<Text style={styles.tagFriendsTitle}>Tag Friends</Text>
</TouchableOpacity>
),
[tags.length],
);
return (
<>
{tagFriendsTitle}
<View style={styles.tagFriendsContainer}>
<ScrollView horizontal>
{tags.map((tag) => (
<TaggedUser key={tag.user.id} {...tag.user} />
))}
{tags.length !== 0 && taggMoreButton}
</ScrollView>
</View>
</>
);
};
const styles = StyleSheet.create({
tagIcon: {width: 20, height: 20, marginRight: '3%'},
tagFriendsTitle: {
color: 'white',
fontSize: normalize(12),
lineHeight: normalize(16.71),
letterSpacing: normalize(0.3),
fontWeight: '600',
},
tagFriendsContainer: {
height: SCREEN_HEIGHT * 0.1,
marginTop: 2,
marginBottom: 5,
},
tagMoreLabel: {
fontWeight: '500',
fontSize: normalize(9),
lineHeight: normalize(10),
letterSpacing: normalize(0.2),
color: 'white',
textAlign: 'center',
},
closeIconContainer: {
width: 20,
height: 20,
right: -20,
zIndex: 1,
},
tagMoreContainer: {
width: 60,
alignItems: 'center',
justifyContent: 'flex-start',
marginTop: -12,
},
tagMoreIcon: {
width: 38,
height: 38,
marginTop: 13,
marginBottom: '10%',
},
taggedUserContainer: {
marginTop: -12,
},
closeIcon: {
width: 20,
height: 20,
left: 15,
top: 10,
},
tagFriendsTitleContainer: {
flexDirection: 'row',
},
});
export default TagFriendsFooter;
|