aboutsummaryrefslogtreecommitdiff
path: root/src/screens/moments/TagFriendsScreen.tsx
blob: b0722efce37caf7a44b1afeb4dcce0ecb36eebd4 (plain)
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
import {RouteProp} from '@react-navigation/core';
import {useNavigation} from '@react-navigation/native';
import React, {useEffect, useRef, useState} from 'react';
import {
  Image,
  Keyboard,
  KeyboardAvoidingView,
  Platform,
  StyleSheet,
  TouchableWithoutFeedback,
  View,
} from 'react-native';
import {Button} from 'react-native-elements';
import {MainStackParams} from 'src/routes';
import {
  CaptionScreenHeader,
  MomentTags,
  SearchBackground,
} from '../../components';
import {TagFriendsFooter} from '../../components/moments';
import {TAGG_LIGHT_BLUE_2} from '../../constants';
import {ProfilePreviewType} from '../../types';
import {SCREEN_WIDTH, StatusBarHeight} from '../../utils';

type TagFriendsScreenRouteProps = RouteProp<
  MainStackParams,
  'TagFriendsScreen'
>;
interface TagFriendsScreenProps {
  route: TagFriendsScreenRouteProps;
}
const TagFriendsScreen: React.FC<TagFriendsScreenProps> = ({route}) => {
  const {image, selectedUsers} = route.params;
  const navigation = useNavigation();
  const imageRef = useRef(null);
  const [taggedUsers, setTaggedUsers] = useState<ProfilePreviewType[]>([]);

  /*
   * Update list of tagged users from route params
   */
  useEffect(() => {
    if (selectedUsers !== undefined) {
      setTaggedUsers(selectedUsers);
    }
  }, [selectedUsers]);

  /*
   * Navigate back to Tag Users Screen, send selected users
   */
  const handleDone = () => {
    navigation.navigate('CaptionScreen', {
      ...route.params,
      selectedUsers: taggedUsers,
    });
  };

  return (
    <SearchBackground>
      <TouchableWithoutFeedback onPress={Keyboard.dismiss}>
        <KeyboardAvoidingView
          behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
          style={styles.flex}>
          <View style={styles.contentContainer}>
            <View style={styles.buttonsContainer}>
              <Button
                title="Cancel"
                buttonStyle={styles.button}
                onPress={() => navigation.goBack()}
              />
              <Button
                title="Done"
                titleStyle={styles.shareButtonTitle}
                buttonStyle={styles.button}
                onPress={handleDone}
              />
            </View>
            <CaptionScreenHeader
              style={styles.header}
              title={'Tap on photo to Tag friends!'}
            />
            <Image
              ref={imageRef}
              style={styles.image}
              source={{uri: image.path}}
              resizeMode={'cover'}
            />
            {taggedUsers.length !== 0 && (
              <MomentTags
                editing={true}
                tags={taggedUsers.map((user) => ({
                  id: '',
                  x: 0,
                  y: 0,
                  user,
                }))}
                imageRef={imageRef}
                deleteFromList={(user) =>
                  setTaggedUsers(taggedUsers.filter((u) => u.id !== user.id))
                }
              />
            )}
            <View style={styles.footerContainer}>
              <TagFriendsFooter
                taggedUsers={taggedUsers}
                setTaggedUsers={setTaggedUsers}
              />
            </View>
          </View>
        </KeyboardAvoidingView>
      </TouchableWithoutFeedback>
    </SearchBackground>
  );
};

const styles = StyleSheet.create({
  contentContainer: {
    paddingTop: StatusBarHeight,
    justifyContent: 'flex-end',
  },
  buttonsContainer: {
    flexDirection: 'row',
    justifyContent: 'space-between',
    marginLeft: '5%',
    marginRight: '5%',
  },
  button: {
    backgroundColor: 'transparent',
  },
  shareButtonTitle: {
    fontWeight: 'bold',
    color: TAGG_LIGHT_BLUE_2,
  },
  header: {
    marginVertical: 20,
  },
  image: {
    position: 'relative',
    width: SCREEN_WIDTH,
    aspectRatio: 1,
    marginBottom: '3%',
  },
  text: {
    position: 'relative',
    backgroundColor: 'white',
    width: '100%',
    paddingHorizontal: '2%',
    paddingVertical: '1%',
    height: 60,
  },
  flex: {
    flex: 1,
  },
  footerContainer: {marginHorizontal: '5%', marginTop: '3%'},
});

export default TagFriendsScreen;