-
Notifications
You must be signed in to change notification settings - Fork 301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lock axis with gesture in the examples? #42
Comments
Here is an updated sandbox without the browser scrolling, with just a minor css fix: |
@dbismut I think you missunderstood my point. we can not always just lock the body with overflow: hidden, would be nice if there a way to lock axis like React pose from popmotion (https://popmotion.io/pose/) see interactivity example. you can also see this example, when you scroll horizontal the browser vertical scroll is ignored |
Sorry I thought your question was related to that specific example.
Question 1Contrary to const [{ x }, set] = useSpring(() => ({ x: 0 }));
const bind = useGesture(({ delta, down }) =>
set({ x: down ? delta[0] : 0, immediate: down })
); // delta[0] contains the x displacement
return (
<animated.div
{...bind()}
style={{ transform: x.interpolate(v => `translateX(${v}px)`) }}
className="square"
/>
); See codesandbox here: https://codesandbox.io/s/6xvp63k19r (note that it doesn't fix the body scroll on mobile) Question 2Did you have a look at #1? You should be able to access the event element. |
The event is passed through, it's part of the event data. but if you're in passive mode you can't call preventDefault, it's forbidden by the browser. You're free to switch passive events off of course. Another possibility would be to simply set the overscroll container to overflow: hidden. that's what i would probably go for. |
Ok, I made it work https://codesandbox.io/embed/y28q726919?codemirror=1 for the scroll but I still think would be good to include the event.preventDefault() into the examples so when user actually testing/playing it with phone, they don't see the page scrolls |
The event is listed on the front-page, look where it says "Event data", that's the generic browser event with all the methods you can call on it. The passive handler stuff is mentioned under config. Passive events are faster and don't cause lag, but it doesn't allow you to stop propagation or prevent defaults. |
thanks for the explanation! |
If you go to the "Draggable List" example in mobile view, dragging items vertically causes the browser to scroll, is there a way to prevent that like preventDefault? I think would be nice to show in the example
https://www.react-spring.io/docs/hooks/examples
The text was updated successfully, but these errors were encountered: