-
Notifications
You must be signed in to change notification settings - Fork 715
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
new(zoom): add pinch and zoom support #1305
Conversation
It seems the build fails because it tries to download from my companies mirror registry. I only have a work laptop so I cannot fix that unless I remove the yarn lock changes completely but that would make it not in sync. Is it possible for someone to fix that minor issue for me? Anything else I can do. |
Wow thanks for the great contribution @tonyneel923 ! ❤️ I will try to take a look at this tomorrow (sorry it's a bigger change so want to look at it more closely!). I just pulled your branch to update the lock file and it allowed me to push to your branch. Sorry if that's not what you meant, my only other thought was to add a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this is looking killer! Just did a quick first pass and will check it out again tomorrow.
I think in the breaking changes (in addition to zoom.containerRef
that you mentioned) we should also note that
props.transformMatrix
was changed to =>initialTransformMatrix
passive
/style
/className
were removed
packages/visx-zoom/src/types.ts
Outdated
@@ -44,6 +46,8 @@ export interface ProvidedZoom { | |||
reset: () => void; | |||
/** Callback for a wheel event, updating scale based on props.wheelDelta, relative to the mouse position. */ | |||
handleWheel: (event: React.WheelEvent | WheelEvent) => void; | |||
/** Callback for a react-use-gesture on pinch event, updating scale based on props.pinchDelta, relative to the pinch position */ | |||
handlePinch: Parameters<typeof useGesture>[0]['onPinch']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like they export UserHandlers
from @use-gesture/react
, so UserHandlers['onPinch']
might work
onPinch: handlePinch, | ||
onWheel: ({ event }) => handleWheel(event), | ||
}, | ||
{ target: containerRef, eventOptions: { passive: false }, drag: { filterTaps: true } }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
options seem legit to me
I am not sure why I did not think of a .npmrc file. We will go with I was tired. Thanks for the feedback on the pr. I will address it today. |
…cess to zoom in callback
I have updated the pr with your requested changes. I also changed pinchDelta to match wheelDelta as I realized the way it was would not work since you would have access to zoom in the callback. I tested on example and it worked perfectly. |
Final note is I changed the test in zoom to not fail but I am not sure why it failed at finding one div because it definitely renders the contents. I do not have much experience with enzyme though and generally use rtl. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woot! @tonyneel923 this looks great to me 🔥 I pulled it locally and tested on my phone 💯
I had a couple super minor comments but then I think it's ready to land! Thanks again for the great addition 🙏 We are coordinating some breaking changes with react@17
, so this may land first as an alpha but will be out soon.
@@ -33,8 +33,7 @@ describe('<Zoom />', () => { | |||
</Zoom>, | |||
); | |||
|
|||
expect(wrapper.find('div')).toHaveLength(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think previously when passive=false
(default), Zoom
wrapped children
in a div
so that's why this is no longer there 👍
…moization to onPinch handler
I added in the changes you requested and I found a way to keep from running getBoundingClientRect all the time using the built in memo parameter in onPinch. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice approach on the memoization! working on a release issue then will merge this 🎉
🎉 This PR is included in version |
🎉 This PR is included in version |
🎉 This PR is included in version |
Hey I appreciate this change! I'm using zoom in a very tight component and it would be really helpful we could be more explicit about breaking changes. For now, I don't feel like I can implement this for fear of introducing bugs. For example, I used Also why the change to Also there are undocumented breakign changes, the interface If there is documentation surrounding this please let me know! |
💥 Breaking Changes
🚀 Enhancements
Zoom now supports mobile pinch.
📝 Documentation
I consolidated the handlers all into react-use-gesture. A user can opt out by not adding the containerRef so it seems like passive was no longer necessary.
In order for mobile zoom to work fully users must add
style={{ touchAction: 'none' }}
to the element in order for the browser to allow js to handle pinch and zoom.Also I had to use the newest version of use-gesture which is technically in beta because of bugs in version 9. By the author's own admission it is ready for production so I do not see an issue with it.
Discussion which prompted this PR: #1292