From 73a77690fa1dd0737f0226e08b19001bc0d676a3 Mon Sep 17 00:00:00 2001 From: Brian Kim Date: Wed, 7 Jul 2021 17:39:19 -0400 Subject: Basic functionality --- src/components/common/MomentTags.tsx | 44 +++++++-- src/screens/moments/TagFriendsScreen.tsx | 159 +++++++++++++++++++++---------- 2 files changed, 146 insertions(+), 57 deletions(-) (limited to 'src') diff --git a/src/components/common/MomentTags.tsx b/src/components/common/MomentTags.tsx index d8a70353..36c87558 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; deleteFromList?: (user: ProfilePreviewType) => void; + boundaries?: DraggableBoundaries; +} +interface DraggableBoundaries { + top?: number; + bottom?: number; + left?: number; + right?: number; } const MomentTags: React.FC = ({ @@ -18,11 +25,16 @@ const MomentTags: React.FC = ({ 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[]>([]); + const [minXBoundary, setMinXBoundary] = useState(0); + const [maxXBoundary, setMaxXBoundary] = useState(0); + const [minYBoundary, setMinYBoundary] = useState(0); + const [maxYBoundary, setMaxYBoundary] = useState(0); const updateTagPosition = (ref: RefObject, userId: string) => { if (ref !== null && ref.current !== null) { @@ -77,6 +89,22 @@ const MomentTags: React.FC = ({ }, ); } + + // Checks for and adds boundaries + if (boundaries) { + if (boundaries.top) { + setMinYBoundary(boundaries.top); + } + if (boundaries.bottom) { + setMaxYBoundary(boundaries.bottom); + } + if (boundaries.left) { + setMinXBoundary(boundaries.left); + } + if (boundaries.right) { + setMaxXBoundary(boundaries.right); + } + } }, editing ? 100 : 0, ); @@ -94,10 +122,10 @@ const MomentTags: React.FC = ({ 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] + minXBoundary} + minY={offset[1] + minYBoundary} + maxX={imageDimensions[0] + offset[0] - maxXBoundary} + maxY={imageDimensions[1] + offset[1] - maxYBoundary} onDragStart={() => { const currZIndex = maxZIndex; setMaxZIndex(currZIndex + 1); @@ -123,10 +151,10 @@ const MomentTags: React.FC = ({ 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] + minXBoundary} + minY={offset[1] + minYBoundary} + maxX={imageDimensions[0] + offset[0] - maxXBoundary} + maxY={imageDimensions[1] + offset[1] - maxYBoundary} disabled={true}> = ({route}) => { setTags(selectedTags ? selectedTags : []); }, [selectedTags]); + /* + * Hide Tab Bar + */ + useFocusEffect( + useCallback(() => { + navigation.dangerouslyGetParent()?.setOptions({ + tabBarVisible: false, + }); + return () => { + navigation.dangerouslyGetParent()?.setOptions({ + tabBarVisible: true, + }); + }; + }, [navigation]), + ); + /* * Navigate back to Tag Users Screen, send selected users */ @@ -49,16 +74,17 @@ const TagFriendsScreen: React.FC = ({route}) => { const setMediaDimensions = (width: number, height: number) => { const imageAspectRatio = width / height; + const screenRatio = SCREEN_WIDTH / SCREEN_HEIGHT; // aspectRatio: >= 1 [Landscape] [1:1] - if (imageAspectRatio >= 1) { + if (imageAspectRatio >= screenRatio) { setImageWidth(SCREEN_WIDTH); setImageHeight(SCREEN_WIDTH / imageAspectRatio); } // aspectRatio: < 1 [Portrait] - if (imageAspectRatio < 1) { - setImageHeight(SCREEN_WIDTH); - setImageWidth(SCREEN_WIDTH * imageAspectRatio); + if (imageAspectRatio < screenRatio) { + setImageHeight(SCREEN_HEIGHT); + setImageWidth(SCREEN_HEIGHT * imageAspectRatio); } }; @@ -78,25 +104,12 @@ const TagFriendsScreen: React.FC = ({route}) => { }, []); return ( - - - -