aboutsummaryrefslogtreecommitdiff
path: root/src/components/taggs/TaggDraggable.tsx
blob: e4448642d1db0cc38842deb07cc4558cac20c88b (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
import {useNavigation} from '@react-navigation/native';
import React, {useEffect, useRef} from 'react';
import {
  Image,
  StyleSheet,
  Text,
  TouchableOpacity,
  TouchableWithoutFeedback,
  View,
} from 'react-native';
import {useDispatch, useSelector} from 'react-redux';
import Avatar from '../../components/common/Avatar';
import {RootState} from '../../store/rootReducer';
import {ProfilePreviewType, ScreenType, UserType} from '../../types';
import {normalize} from '../../utils';
import {navigateToProfile} from '../../utils/users';

interface TaggDraggableProps {
  taggedUser: ProfilePreviewType;
  editingView: boolean;
  deleteFromList: () => void;
  setStart: Function;
}

const TaggDraggable: React.FC<TaggDraggableProps> = (
  props: TaggDraggableProps,
) => {
  const navigation = useNavigation();
  const dispatch = useDispatch();
  const state = useSelector((rs: RootState) => rs);
  const {taggedUser, editingView, deleteFromList, setStart} = props;
  let uriX = require('../../assets/images/draggableX.png');
  let uriTip = require('../../assets/images/Tagg-Triangle.png');

  const draggableRef = useRef(null);

  useEffect(() => {
    draggableRef.current.measure((width: number, height: number) => {
      setStart([width, height]);
    });
  }, []);

  const user: UserType = {
    userId: taggedUser.id,
    username: taggedUser.username,
  };

  return (
    <TouchableWithoutFeedback>
      <View style={styles.container}>
        <Image style={styles.imageTip} source={uriTip} />
        <TouchableOpacity
          onPressIn={() =>
            navigateToProfile(
              state,
              dispatch,
              navigation,
              ScreenType.Profile,
              user,
            )
          }
          disabled={editingView}
          style={styles.content}
          ref={draggableRef}>
          <Avatar style={styles.avatar} uri={taggedUser.thumbnail_url} />
          <Text style={editingView ? styles.buttonTitle : styles.buttonTitleX}>
            @{taggedUser.username}
          </Text>
          {editingView && (
            <TouchableOpacity
              disabled={false}
              onPressIn={deleteFromList}
              style={styles.imageX}>
              <Image style={styles.imageX} source={uriX} />
            </TouchableOpacity>
          )}
        </TouchableOpacity>
      </View>
    </TouchableWithoutFeedback>
  );
};

const styles = StyleSheet.create({
  imageTip: {
    height: normalize(12),
    aspectRatio: 12 / 8,
  },
  container: {
    flexDirection: 'column',
    alignItems: 'center',
    justifyContent: 'center',
  },
  buttonTitle: {
    color: 'white',
    fontSize: normalize(11),
    fontWeight: '700',
    lineHeight: normalize(13.13),
    letterSpacing: normalize(0.6),
    paddingHorizontal: '1%',
  },
  buttonTitleX: {
    color: 'white',
    fontSize: normalize(11),
    fontWeight: '700',
    lineHeight: normalize(13.13),
    letterSpacing: normalize(0.6),
    paddingHorizontal: '1%',
  },
  avatar: {
    height: normalize(20),
    width: normalize(20),
    borderRadius: normalize(20) / 2,
  },
  imageX: {
    width: normalize(15),
    height: normalize(15),
  },
  content: {
    justifyContent: 'space-evenly',
    alignItems: 'center',
    flexDirection: 'row',
    borderRadius: 20,
    paddingVertical: normalize(5),
    paddingHorizontal: normalize(8),
    backgroundColor: 'rgba(0, 0, 0, 0.8)',
  },
});

export default TaggDraggable;