From 824a12b9918387fbb45c86628b6a2cbe6ac713b7 Mon Sep 17 00:00:00 2001 From: corgifist Date: Sun, 3 Aug 2025 15:25:44 +0300 Subject: [PATCH] trying to defeat accidental project deletion thing --- .../swipe-to-delete/SwipeToDelete.tsx | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/components/swipe-to-delete/SwipeToDelete.tsx b/src/components/swipe-to-delete/SwipeToDelete.tsx index 5e3b6da..9b2717c 100644 --- a/src/components/swipe-to-delete/SwipeToDelete.tsx +++ b/src/components/swipe-to-delete/SwipeToDelete.tsx @@ -81,15 +81,18 @@ const SwipeToDelete: FC = ({ lastTimeRef.current = now; lastXRef.current = pageX; lastYRef.current = pageY; - if (Math.abs(dy) > 5 && Math.abs(dragX) < 10) { - return; - } + const raw = pageX - startX; - const x = dragX < 0 ? rubber(raw) : rubber(raw, width * 0.1); - if (x < 0) setAllowOverscroll(true); - if (x <= 0 || (allowOverscroll && x >= 0)) setDragX(x); - if (Math.abs(vY) < 5) document.body.classList.add('no-scroll'); + let x = dragX < 0 ? rubber(raw) : rubber(raw, width * 0.1); + if ((Math.abs(dragX) === 0 ? Math.abs(vY) < window.innerHeight * 0.05 : true)) { + if (x < 0) setAllowOverscroll(true); + if (x <= 0 || (allowOverscroll && x >= 0)) setDragX(x); + } else { + setDragX(0); + setAllowOverscroll(false); + } + if (Math.abs(vY) < 20) document.body.classList.add('no-scroll'); }; const handleDelete = () => { @@ -112,13 +115,21 @@ const SwipeToDelete: FC = ({ velocity < -1000; setAllowOverscroll(false); document.body.classList.remove('no-scroll'); + if (Math.abs(velocityY) > window.innerHeight * 0.05) { + setDragX(0); + setDragX(0); + if (transparencyTimeout) { + clearTimeout(transparencyTimeout); + } + setForceTransparentBackground(true); + transparencyTimeout = setTimeout(() => setForceTransparentBackground(false), 150); + return; + } if (!shouldDelete) { content.current?.classList.add('ios-ease'); text.current?.classList.add('ios-ease'); - - const textWidth = text.current ? text.current.getBoundingClientRect().width : 0; - if (((velocity < 0 && Math.abs(velocity) > 10) || dragX < -textWidth * 1.5 && velocity > 0) && text.current && (Math.abs(dragX) < 30 ? Math.abs(velocityY) < 5 : true)) { + if (((velocity < 0 && Math.abs(velocity) > 10) || dragX < -textWidth * 1.5 && velocity > 0) && text.current) { setDragX(-textWidth * 1.5); } else if (allowOverscroll && dragX > 0) { setDragX(0);