From c8f490adfb241f87df8d573e8fbc0e04a27edd10 Mon Sep 17 00:00:00 2001 From: Gigiaj Date: Sun, 15 Jun 2025 22:20:04 -0500 Subject: [PATCH] Add draggablemessage --- .../room/message/DraggableMessage.tsx | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 src/app/features/room/message/DraggableMessage.tsx diff --git a/src/app/features/room/message/DraggableMessage.tsx b/src/app/features/room/message/DraggableMessage.tsx new file mode 100644 index 00000000..4476d5c7 --- /dev/null +++ b/src/app/features/room/message/DraggableMessage.tsx @@ -0,0 +1,100 @@ +import React from 'react'; +import { useSpring, animated } from '@react-spring/web'; +import { useDrag } from 'react-use-gesture'; +import { Icon, Icons } from 'folds'; + +const DraggableMessageStyles = { + container: { + position: 'relative', + overflow: 'hidden', + width: '100%', + }, + replyIconContainer: { + position: 'absolute', + top: 0, + bottom: 0, + right: 0, + display: 'flex', + alignItems: 'center', + justifyContent: 'center', + width: '80px', + }, + messageContent: { + position: 'relative', + touchAction: 'pan-y', + backgroundColor: 'var(--folds-color-Background-Main)', + width: '100%', + }, +}; + +export function DraggableMessage({ children, onReply }) { + const REPLY_THRESHOLD = 80; + + const [{ x, iconScale }, api] = useSpring(() => ({ + x: 0, + iconScale: 0.5, + config: { tension: 250, friction: 25 }, + })); + + const bind = useDrag( + ({ down, movement: [mx], direction: [xDir], vxvy: [vx], cancel }) => { + if (!down && Math.abs(xDir) < 0.7) { + cancel(); + } + + const xTarget = down ? Math.min(0, mx) : 0; + let scaleTarget = down + ? 0.5 + Math.min(Math.abs(mx), REPLY_THRESHOLD) / (REPLY_THRESHOLD * 2) + : 0.5; + + if (mx < -REPLY_THRESHOLD) { + onReply(); + } + + /* + if (!down) { + if (mx < -REPLY_THRESHOLD && vx < -0.5) { + onReply(); + } + } else { + if (mx < -REPLY_THRESHOLD) { + scaleTarget = 1; + } + } +*/ + api.start({ + x: xTarget, + iconScale: scaleTarget, + }); + }, + { + axis: 'x', + filterTaps: true, + threshold: 10, + } + ); + + return ( +
+ `scale(${s})`), + opacity: iconScale.to((s) => (s - 0.5) * 2), + }} + > + + + + + {children} + +
+ ); +}