aboutsummaryrefslogtreecommitdiff
path: root/src/screens/profile/CaptionScreen.tsx
diff options
context:
space:
mode:
authorIvan Chen <ivan@tagg.id>2021-05-21 19:18:44 -0400
committerIvan Chen <ivan@tagg.id>2021-05-21 19:18:44 -0400
commitb9930f62d502332ae3cf2e0e20a7743a3d7e1df1 (patch)
tree68ebd2dacc7b61d60cfaac7f68cd3bc5c4a133a8 /src/screens/profile/CaptionScreen.tsx
parentace995d7d0ceb3b0c012f6c29808c05bdb26fe71 (diff)
parent9315aa31ad4d6c305e62853a3ab7e4a484ecce98 (diff)
Merge branch 'master' into tma884-moment-view-tags
Diffstat (limited to 'src/screens/profile/CaptionScreen.tsx')
-rw-r--r--src/screens/profile/CaptionScreen.tsx68
1 files changed, 67 insertions, 1 deletions
diff --git a/src/screens/profile/CaptionScreen.tsx b/src/screens/profile/CaptionScreen.tsx
index a41abba6..8e972e07 100644
--- a/src/screens/profile/CaptionScreen.tsx
+++ b/src/screens/profile/CaptionScreen.tsx
@@ -1,6 +1,6 @@
import {RouteProp} from '@react-navigation/native';
import {StackNavigationProp} from '@react-navigation/stack';
-import React, {Fragment, useState} from 'react';
+import React, {Fragment, useEffect, useRef, useState} from 'react';
import {
Alert,
Image,
@@ -16,7 +16,9 @@ import {Button} from 'react-native-elements';
import {useDispatch, useSelector} from 'react-redux';
import {SearchBackground} from '../../components';
import {CaptionScreenHeader} from '../../components/';
+import Draggable from '../../components/common/Draggable';
import TaggLoadingIndicator from '../../components/common/TaggLoadingIndicator';
+import TaggDraggable from '../../components/taggs/TaggDraggable';
import {TAGG_LIGHT_BLUE_2} from '../../constants';
import {ERROR_UPLOAD, SUCCESS_PIC_UPLOAD} from '../../constants/strings';
import {MainStackParams} from '../../routes';
@@ -50,6 +52,39 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => {
const dispatch = useDispatch();
const [caption, setCaption] = useState('');
const [loading, setLoading] = useState(false);
+ const imageRef = useRef(null);
+
+ // state variables used to position draggables
+ const [offset, setOffset] = useState([0, 0]);
+ const [curStart, setCurStart] = useState([0, 0]);
+ const [imageDimensions, setImageDimensions] = useState([0, 0]);
+
+ const [taggList, setTaggList] = useState([
+ {
+ first_name: 'Ivan',
+ id: 'cee45bf8-7f3d-43c8-99bb-ec04908efe58',
+ last_name: 'Chen',
+ thumbnail_url:
+ 'https://tagg-dev.s3.us-east-2.amazonaws.com/thumbnails/smallProfilePicture/spp-cee45bf8-7f3d-43c8-99bb-ec04908efe58-thumbnail.jpg',
+ username: 'ivan.tagg',
+ },
+ {
+ first_name: 'Ankit',
+ id: '3bcf6947-bee6-46b0-ad02-6f4d25eaeac3',
+ last_name: 'Thanekar',
+ thumbnail_url:
+ 'https://tagg-dev.s3.us-east-2.amazonaws.com/thumbnails/smallProfilePicture/spp-3bcf6947-bee6-46b0-ad02-6f4d25eaeac3-thumbnail.jpg',
+ username: 'ankit.thanekar',
+ },
+ {
+ first_name: 'Ankit',
+ id: '3bcf6947-bee6-46b0-ad02-6f4d25eaeac3',
+ last_name: 'Thanekar',
+ thumbnail_url:
+ 'https://tagg-dev.s3.us-east-2.amazonaws.com/thumbnails/smallProfilePicture/spp-3bcf6947-bee6-46b0-ad02-6f4d25eaeac3-thumbnail.jpg',
+ username: 'ankit.thanekar',
+ },
+ ]);
const navigateToProfile = () => {
//Since the logged In User is navigating to own profile, useXId is not required
@@ -59,6 +94,16 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => {
});
};
+ /**
+ * need a handler to take care of creating a tagged user object, append that object to the taggList state variable.
+ */
+ useEffect(() => {
+ imageRef.current.measure((fx, fy, width, height, px, py) => {
+ setOffset([px, py]);
+ setImageDimensions([width, height]);
+ });
+ }, []);
+
const handleShare = async () => {
setLoading(true);
if (!image.filename) {
@@ -105,7 +150,9 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => {
/>
</View>
<CaptionScreenHeader style={styles.header} {...{title: title}} />
+ {/* this is the image we want to center our tags' initial location within */}
<Image
+ ref={imageRef}
style={styles.image}
source={{uri: image.path}}
resizeMode={'cover'}
@@ -118,6 +165,25 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => {
onChange={setCaption}
partTypes={mentionPartTypes('blue')}
/>
+ {taggList.map((user) => (
+ <Draggable
+ x={imageDimensions[0] / 2 - curStart[0] / 2 + offset[0]}
+ y={offset[1] + imageDimensions[1] / 2 - curStart[1] / 2}
+ minX={offset[0]}
+ minY={offset[1]}
+ maxX={imageDimensions[0] + offset[0]}
+ maxY={imageDimensions[1] + offset[1]}
+ onDragStart={() => null}>
+ <TaggDraggable
+ taggedUser={user}
+ editingView={true}
+ deleteFromList={() =>
+ setTaggList(taggList.filter((u) => u.id !== user.id))
+ }
+ setStart={setCurStart}
+ />
+ </Draggable>
+ ))}
</View>
</KeyboardAvoidingView>
</TouchableWithoutFeedback>