-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
Prevent jump when zooming out with double tap #292
Prevent jump when zooming out with double tap #292
Conversation
Run & review this pull request in StackBlitz Codeflow. |
✅ Deploy Preview for zoom-image-library ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
One note on the side: I've also removed the If you see a reason why we shouldn't change this then I'm happy to add it back in. Feel free to object on that |
Also, do you need me to run the changeset command again? |
Yeah, everything looks great. Just please add changeset as it will make my job easy to release it 😊 |
function lerp(a: number, b: number, t: number): number { | ||
return a * (1 - t) + b * t | ||
} |
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.
Oh man, thanks so much! I really miss Math back in university and high school ❤️ What I do nowadays in the industry as FrontEnd engineer has almost nothing to do with numbers, mostly logic 🙈 I should start spending more time on this beautiful stuff 😍
done :) |
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.
Thanks again for your beautiful PR 🫶, you opened my mind 😊
Hi, I'm back with another PR :)
This time I took a look at the zooming animation that appears when double-tapping. Specifically, when zooming out, the previous implementation sometimes had a visual jump at the start of the zoom-out animation. I recorded an example in this video:
zoomout-old.webm
The problem was that the
x
andy
variables were updated on every touch, meaning that when zooming out, the zoom location would first jump to the coordinate where the touch happened. My first instinct to fix this was to just only update the coordinates when zooming in, and leave them at the same value when zooming out. Unfortunately this doesn't work, since the start of the zoom-out animation will be wherever the zoom-in animation ended, and thus will still jump if the user has panned around in the meantime.To fix this, I had to make some significant changes to the
animateZoom
function. This function now starts by determining a start and end location for the zoom animation, and then only passing an inner function torequestAnimationFrame
instead of re-running the calculations on every frame. The start of the zoom-out animation can now be computed from the current state.The new behaviour looks like this:
zoomout-new.webm
I believe that these changes also make the
animateZoom
function more readable, but of course I'm biased since this time I'm the one who wrote it 😅 so I'll let you be the judge of that