usehooks
usehooks copied to clipboard
onLongPress : movement during press
Hi
I'm using useLongpress hook, and it's working fine, but when users scrolls, i do not want the event to be fired, or i would have the ability to detect move in the event parameter.
Do you think it's possible ? Am I missing something already existing ?
Regards.
+1
For anyone looking for this still, a solution that seems to be working great for me is to simply track the current scroll position at start use it to compare with the current scroll position when the callback is fired.
Something like:
const startScrollLocation = useRef()
const attrs = useLongPress(
() => {
const movement = Math.abs(startScrollLocation.current - scrollContainerRef.current?.scrollTop)
if (movement > 20) return
fireTheCallback()
},
{
onStart: () => (startScrollLocation.current = scrollContainerRef.current?.scrollTop),
onFinish: () => (startScrollLocation.current = null),
threshold: 350,
}
)