diff options
author | Ivan Chen <ivan@tagg.id> | 2021-07-09 12:37:55 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-09 12:37:55 -0400 |
commit | a6a5f40650d43854b06aca1f228da99c1014c671 (patch) | |
tree | f70c333a0fb2b1792feb98711269fee5027449d0 /src/components/common | |
parent | 083675eec3ff5b7122e43097fe565afb78beec46 (diff) | |
parent | e62ba8ca223d92f662016445264030d28009288f (diff) |
Merge pull request #492 from brian-tagg/tma968-new-moment-tagging
[TMA-968] New Moment Tagging Flow
Diffstat (limited to 'src/components/common')
-rw-r--r-- | src/components/common/MomentTags.tsx | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/src/components/common/MomentTags.tsx b/src/components/common/MomentTags.tsx index d8a70353..37069e18 100644 --- a/src/components/common/MomentTags.tsx +++ b/src/components/common/MomentTags.tsx @@ -10,6 +10,13 @@ interface MomentTagsProps { setTags: (tag: MomentTagType[]) => void; imageRef: RefObject<Image>; deleteFromList?: (user: ProfilePreviewType) => void; + boundaries?: DraggableBoundaries; +} +interface DraggableBoundaries { + top?: number; + bottom?: number; + left?: number; + right?: number; } const MomentTags: React.FC<MomentTagsProps> = ({ @@ -18,11 +25,14 @@ const MomentTags: React.FC<MomentTagsProps> = ({ setTags, imageRef, deleteFromList, + boundaries, }) => { const [offset, setOffset] = useState([0, 0]); const [imageDimensions, setImageDimensions] = useState([0, 0]); const [maxZIndex, setMaxZIndex] = useState(1); const [draggableRefs, setDraggableRefs] = useState<RefObject<View>[]>([]); + // [minXBoundary, maxXBoundary, minYBoundary, maxYBoundary] + const [boundariesList, setBoundariesList] = useState<number[]>([0, 0, 0, 0]); const updateTagPosition = (ref: RefObject<Image>, userId: string) => { if (ref !== null && ref.current !== null) { @@ -77,6 +87,24 @@ const MomentTags: React.FC<MomentTagsProps> = ({ }, ); } + + // Checks for and adds boundaries + if (boundaries) { + const newBounds = [...boundariesList]; + if (boundaries.top) { + newBounds[2] = boundaries.top; + } + if (boundaries.bottom) { + newBounds[3] = boundaries.bottom; + } + if (boundaries.left) { + newBounds[0] = boundaries.left; + } + if (boundaries.right) { + newBounds[1] = boundaries.right; + } + setBoundariesList(newBounds); + } }, editing ? 100 : 0, ); @@ -94,10 +122,10 @@ const MomentTags: React.FC<MomentTagsProps> = ({ x={(imageDimensions[0] * tag.x) / 100 + offset[0]} y={(imageDimensions[1] * tag.y) / 100 + offset[1]} z={tag.z} - minX={offset[0]} - minY={offset[1]} - maxX={imageDimensions[0] + offset[0]} - maxY={imageDimensions[1] + offset[1]} + minX={offset[0] + boundariesList[0]} + minY={offset[1] + boundariesList[2]} + maxX={imageDimensions[0] + offset[0] - boundariesList[1]} + maxY={imageDimensions[1] + offset[1] - boundariesList[3]} onDragStart={() => { const currZIndex = maxZIndex; setMaxZIndex(currZIndex + 1); @@ -123,10 +151,10 @@ const MomentTags: React.FC<MomentTagsProps> = ({ x={(imageDimensions[0] * tag.x) / 100 + offset[0]} y={(imageDimensions[1] * tag.y) / 100 + offset[1]} z={tag.z} - minX={offset[0]} - minY={offset[1]} - maxX={imageDimensions[0] + offset[0]} - maxY={imageDimensions[1] + offset[1]} + minX={offset[0] + boundariesList[0]} + minY={offset[1] + boundariesList[2]} + maxX={imageDimensions[0] + offset[0] - boundariesList[1]} + maxY={imageDimensions[1] + offset[1] - boundariesList[3]} disabled={true}> <TaggDraggable draggableRef={draggableRefs[index]} |