From a5ef509d2a1f79d85c76ee766dabe96acac2a989 Mon Sep 17 00:00:00 2001 From: George Rusu Date: Tue, 25 May 2021 13:22:52 -0700 Subject: Add layering functionality when editing tags --- src/components/common/Draggable.tsx | 29 ++++++++++---------- src/components/common/MomentTags.tsx | 17 +++++++++--- src/components/moments/MomentPostContent.tsx | 40 +++++++++++++++++++++++----- src/screens/profile/CaptionScreen.tsx | 1 + src/types/types.ts | 1 + 5 files changed, 63 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/components/common/Draggable.tsx b/src/components/common/Draggable.tsx index edd29b78..1253fed4 100644 --- a/src/components/common/Draggable.tsx +++ b/src/components/common/Draggable.tsx @@ -59,7 +59,7 @@ interface IProps { minY?: number; maxX?: number; maxY?: number; - onDragStart?: () => void; + onDragStart?: () => number; } export default function Draggable(props: IProps) { @@ -103,8 +103,8 @@ export default function Draggable(props: IProps) { // Whether we're currently dragging or not const isDragging = React.useRef(false); - // const [zIndex, setZIndex] = React.useState(z); - const zIndex = z; + const [zIndex, setZIndex] = React.useState(z); + // const zIndex = z; const getBounds = React.useCallback(() => { const left = x + offsetFromStart.current.x; @@ -147,18 +147,17 @@ export default function Draggable(props: IProps) { [onDragRelease, shouldReverse, onRelease, reversePosition], ); - const onPanResponderGrant = React.useCallback( - (_: GestureResponderEvent) => { - startBounds.current = getBounds(); - isDragging.current = true; - if (!shouldReverse) { - pan.current.setOffset(offsetFromStart.current); - pan.current.setValue({x: 0, y: 0}); - } - onDragStart(); - }, - [getBounds, shouldReverse], - ); + const onPanResponderGrant = (_: GestureResponderEvent) => { + startBounds.current = getBounds(); + isDragging.current = true; + if (!shouldReverse) { + pan.current.setOffset(offsetFromStart.current); + pan.current.setValue({x: 0, y: 0}); + } + if (onDragStart) { + setZIndex(onDragStart()); + } + }; const handleOnDrag = React.useCallback( (e: GestureResponderEvent, gestureState: PanResponderGestureState) => { diff --git a/src/components/common/MomentTags.tsx b/src/components/common/MomentTags.tsx index 04b0558b..9a6cd08b 100644 --- a/src/components/common/MomentTags.tsx +++ b/src/components/common/MomentTags.tsx @@ -19,6 +19,7 @@ const MomentTags: React.FC = ({ const [offset, setOffset] = useState([0, 0]); const [curStart, setCurStart] = useState([0, 0]); const [imageDimensions, setImageDimensions] = useState([0, 0]); + const [maxZIndex, setMaxZIndex] = useState(1); useEffect(() => { imageRef.current.measure((fx, fy, width, height, px, py) => { @@ -34,17 +35,25 @@ const MomentTags: React.FC = ({ <> {tags.map((tag) => ( null}> + onDragStart={() => { + const currZIndex = maxZIndex; + setMaxZIndex(currZIndex + 1); + return currZIndex; + }}> deleteFromList(tag.user)} + deleteFromList={() => { + deleteFromList(tag.user); + }} setStart={setCurStart} /> @@ -54,13 +63,15 @@ const MomentTags: React.FC = ({ <> {tags.map((tag) => ( null}> + disabled={true}> = ({ fetchCommentsCount(); }, [dateTime, momentId]); + useEffect(() => { + const fade = async () => { + Animated.timing(fadeValue, { + toValue: 1, + duration: 250, + easing: Easing.linear, + }).start(); + }; + fade(); + }, [fadeValue]); + return ( - - + { + setVisible(!visible); + setFadeValue(new Animated.Value(0)); + }}> + + + {visible && ( + + + + )} = ({route, navigation}) => { taggedUsers.map((u, index) => ({ x: index * 50 - 150, y: index * 50 - 150, + z: 1, user_id: u.id, })), ); diff --git a/src/types/types.ts b/src/types/types.ts index e957483b..b294e3f1 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -123,6 +123,7 @@ export interface MomentTagType { user: ProfilePreviewType; x: number; y: number; + z: number; } export interface CommentBaseType { -- cgit v1.2.3-70-g09d2