retyui / react-quick-pinch-zoom

A react component that providing multi-touch gestures for zooming and dragging on any DOM element.
https://react-quick-pinch-zoom.netlify.app/
310 stars 47 forks source link

Add prop to prevent moving child that is smaller than container #73

Closed tf closed 1 year ago

tf commented 1 year ago

So far, when external styles force the container to be larger than the child, _sanitizeOffset always allowed moving the child inside the container:

https://github.com/retyui/react-quick-pinch-zoom/assets/26554/fa41b90c-74ac-4d1f-b7d5-640c4d39ad4f

Especially on portrait screens it can make sense to use a viewport sized container. A landscape image will initially be centered and scaled to fit into the container. Once the image is zoomed the whole viewport can be used to view the image.

As long as the image still fits into the viewport vertically, it does not make sense to allow moving it vertically. There already is a prop draggableUnZoomed which prevents dragging the image while it has not been zoomed. Soon as the image has only slightly been zoomed, it can again be moved out of the center vertically.

This commit adds a centerContained prop to allow ensuring that images remain centered as long as they still fit into the container.

This PR contains commits that perform the following steps:

Finally, yarn size started failing since the changes pushed us over the limit. So far tests were also considered in the total size, which does not make sense, I think. So I ignored those to push us under the limit. Not sure if the limit is a specifically chosen target site or if it is just about noticing when the code gets bigger.

tf commented 1 year ago

Forgot to include the video of the "after" case:

https://github.com/retyui/react-quick-pinch-zoom/assets/26554/c98236fe-23f3-44c1-b2d1-6bf77a8098b8

retyui commented 1 year ago

Thanks!

Released 4.8.0

diff: 4.7.0...4.8.0