a tool for shared writing and social publishing
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cancel longpress on touchmove great than threshold

+14
+14
src/hooks/useLongPress.ts
··· 45 45 } 46 46 }; 47 47 window.addEventListener("mousemove", listener); 48 + let touchListener = (e: TouchEvent) => { 49 + if (e.touches[0]) { 50 + const distance = Math.sqrt( 51 + Math.pow(e.touches[0].clientX - startPosition.x, 2) + 52 + Math.pow(e.touches[0].clientY - startPosition.y, 2), 53 + ); 54 + if (distance > 16) { 55 + end(); 56 + } 57 + } 58 + }; 59 + window.addEventListener("touchmove", touchListener); 60 + 48 61 return () => { 49 62 window.removeEventListener("mousemove", listener); 63 + window.removeEventListener("touchmove", touchListener); 50 64 }; 51 65 } 52 66 }, [startPosition, end]);