Gesture with wheel and drag bugs drag bounds. #329
-
I have a canvas, and I want to move the camera down or up on the canvas, like scrolling a page, either by actually wheeling (useful on PC) or by dragging (to also be mobile friendly). If I wheel, I want the gesture to clamp at the page beginning or end, and If I drag, I want it to be a little rubberband effect on the same page limits. https://codesandbox.io/s/use-gesture-test-i3n9o?file=/src/App.js What am I missing and how would I implement this (scrolling or dragging - with rubberband ) to move the camera if not this way? That doesn't seem like a complex use case but I can't find any example on that anywhere. Please help! And thanks very much! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
A few things worth noticing: there's no need to use the Here's a working sandbox (at least I think in my rapid testing): https://codesandbox.io/s/dreamy-sound-wutk2 Working on this sandbox makes me realize that there might be something to be done to make bounds work better when wheel is changing direction (completely unrelated to your problem). |
Beta Was this translation helpful? Give feedback.
A few things worth noticing: there's no need to use the
useCallback
hook for handlers. TheuseGesture
hook is recomputed on every render whether the handler function reference changes or not. In that case it just adds complexity and aif / else
condition relying onevent.type
which is not always safe with this lib.Here's a working sandbox (at least I think in my rapid testing): https://codesandbox.io/s/dreamy-sound-wutk2
I haven't used
rollSpeed
as this is typically the sort of complexity overload that I don't want to deal with when solving issues.Working on this sandbox makes me realize that there might be something to be done to make bounds work better when wheel is changing direction…