Comments (6)
Hey Matt, thanks for the kind words! Unless there’s something I’m missing, you should use the exact same strategy as for the drag boundaries example, ie clamping the delta and using memo
to retain the initial wheel value as you suggested in your last paragraph.
from use-gesture.
Hmm, Maybe I need to build an example.
The issue is that the delta
which my handler is called with is not clamped, just the final scroll position.
E.g.
- You start with 100px below your current position
- You scroll down 200px, however, the clamp stops you at 100px
- If you scroll up 100px in the same gesture... what happens?
What I currently see is no motion. The delta my handler gets has gone from 200 to 100, but the whole time we've been clamped at 100px, so nothing has moved.
What I'd like to achieve is, as soon as you start scrolling down, it starts moving again. In this example, you'd be back at your initial position.
Edit: Created a basic example from the current one... Try scrolling the box around a little bit, especially near the boundaries. https://codesandbox.io/s/boundaries-z28ew
from use-gesture.
Hadn't seen your edit sorry, well... your example works fine, no? make sure you're actually testing in a new window, as it seems that onWheel
events on window
don't seem to be triggered properly in the csb iframe.
Btw, here's your csb tweaked using the latest versions of react-use-gesture
and react-spring
: https://codesandbox.io/s/boundaries-r3dj7
And here is a csb showing that boundaries work properly: https://codesandbox.io/s/react-use-gesture-issue-wheel-n89rq
The left black square shows the clamped y wheel value (boundaries are [-1000,1000]
), the right white square shows the unclamped local
value.
Btw, this gave me the opportunity to fix a bug in memo
, 5.2.4
is now released on npm ;)
EDIT: ok I understand where the issue is after playing with it once more. Wheeling up past the boundaries and then wheeling down doesn't reset memo. I'll find a fix.
EDIT2: now my csb should be working (hopefully!!), I think the code is self explanatory. However, I wonder if the handler shouldn't give xy - previous
right away to avoid you making the calculation.
from use-gesture.
Yep, thats exactly the idea! Your solution does what was I was trying to get to!
As for xy-prev
I think it would be a decent api to include since the browser scroll event provides an event.deltaX
and event.deltaY
which are "local to each independent event". When I first started using this library it took me a second to realize that delta
was "local to the gesture".
I'm also probably using "local" in a weird way, because local to this library also means a sort of persistent state.
In any case, thank you for your time in helping me. You guys are way too gracious! :)
Feel free to close this issue, unless you want to use it as a holder for including the above api.
from use-gesture.
Sure, happy to help, it’s useful to face common problems and in that situation it also allowed me to spot a bug.
Yeah, local and delta concepts were a bit weird to me too (not to mention memo) when I took over the lib, but they really feel natural now.
When you mention the scroll event and deltas I presume you meant the wheel event. That’s true, and actually the lib sums the event deltas so that you’re able to know how much you’ve wheeled, and I do understand the confusion with the lib definition of delta.
But it’s too late to change delta for something else so I’d have to find a new name for the xy-previous
delta! If you have any suggestions please shoot and I’ll add it in 5.2.5.
from use-gesture.
For info, we’ll rename delta
to movement
, current - previous
will be labeled delta
and local
is relabeled offset
. That will be a breaking change, so planned for v6.
from use-gesture.
Related Issues (20)
- Pinch bug: after opening/closing context menu, pinching gesture can be fired with 1 finger HOT 1
- Delegate drag to remaining finger after pinch or support multi-finger drag HOT 5
- Using modifierKey causes the mac pinch event to return HOT 2
- Using pointer.touch cannot be dragged under windows system HOT 6
- useDrag breaks onClick listener in React portal to shadow dom HOT 2
- using video element inside useDrag component doesn't allow the video to play/pause using single click over the video HOT 6
- DragBounds ignored when rerender target HOT 1
- dynamically updating useDrags axis option resets movement : [mx,my] HOT 2
- Using alt+left for navigation prevents all gestures on elements with axis: 'y'
- Drag gesture: Delay setting behavior does not adhere to documentation HOT 4
- Drag + Click + filtertaps option breaks onclick listener. Drag + Click + Treshold works. HOT 1
- touch-action: pan-y prevents L shaped gestures to scroll
- onPinch breaking on control + scroll HOT 5
- Where do I import a3f from? HOT 1
- Getting the error "a3f is not defined"
- Textarea doesn't work inside gesture container HOT 4
- Documentation website is broken (in firefox) HOT 8
- Type error with @types/react >=18.2.66
- (Firefox) Click event fired on drag end
- 100ms delay between pointermove events in Android webviews? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from use-gesture.