From a8f095c734b748b38e2ac50483c41923ab0078f6 Mon Sep 17 00:00:00 2001 From: Brian Kim Date: Wed, 19 May 2021 15:10:04 -0700 Subject: Set middle placement --- src/components/taggs/TaggDraggable.tsx | 28 +++++++++++++++++++++++++--- src/screens/profile/CaptionScreen.tsx | 13 ++++++++++--- 2 files changed, 35 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/components/taggs/TaggDraggable.tsx b/src/components/taggs/TaggDraggable.tsx index bd0d01bd..0d57c590 100644 --- a/src/components/taggs/TaggDraggable.tsx +++ b/src/components/taggs/TaggDraggable.tsx @@ -1,5 +1,5 @@ import {useNavigation} from '@react-navigation/native'; -import React, {useState} from 'react'; +import React, {useState, useEffect, useRef} from 'react'; import { Image, StyleSheet, @@ -13,6 +13,7 @@ import {RootState} from '../../store/rootReducer'; import {ScreenType, UserType} from '../../types'; import {normalize, SCREEN_HEIGHT, SCREEN_WIDTH} from '../../utils'; import TaggAvatar from '../profile/TaggAvatar'; +import {RefObject} from 'react'; interface TaggDraggableProps { draggable?: boolean; @@ -23,6 +24,7 @@ interface TaggDraggableProps { taggedUser: UserType; redirect: boolean; deleteFromList: () => void; + setStart: Function; } const TaggDraggable: React.FC = ( @@ -42,14 +44,34 @@ const TaggDraggable: React.FC = ( taggedUser, redirect, deleteFromList, + setStart, } = props; let uriTip = require('../../assets/images/tagg-tip.png'); let uriX = require('../../assets/images/draggableX.png'); + const draggableRef = useRef(null); + + useEffect(() => { + draggableRef.current.measure((fx, fy, width, height, px, py) => { + console.log('Drag Component width is: ' + width); + console.log('Drag Component height is: ' + height); + console.log('X offset to frame: ' + fx); + console.log('Y offset to frame: ' + fy); + console.log('X offset to page: ' + px); + console.log('Y offset to page: ' + py); + setStart([width, height]); + }); + }, []); + return ( - - + console.log(event.nativeEvent.layout)}> + = ({route, navigation}) => { // created a state variable to keep track of every tag // idea is that each element in the list const [taggList, setTaggList] = useState([]); - const draggableRef = useRef(null); const imageRef = useRef(null); const [tagInitCoords, setTagInitCoords] = useState([]); + const [offset, setOffset] = useState([0, 0]); + + const [curStart, setCurStart] = useState([0, 0]); + const [dim, setDim] = useState([0, 0]); const navigateToProfile = () => { //Since the logged In User is navigating to own profile, useXId is not required @@ -93,6 +96,8 @@ const CaptionScreen: React.FC = ({route, navigation}) => { console.log('Y offset to frame: ' + fy); console.log('X offset to page: ' + px); console.log('Y offset to page: ' + py); + setOffset([px, py]); + setDim([width, height]); }); }, []); @@ -157,9 +162,10 @@ const CaptionScreen: React.FC = ({route, navigation}) => { onChange={setCaption} partTypes={mentionPartTypes('blue')} /> - + = ({route, navigation}) => { taggedUser={user} redirect={true} deleteFromList={() => console.log('Hello world')} + setStart={setCurStart} /> -- cgit v1.2.3-70-g09d2