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:
Extract previous _sanitizeOffset logic into a separate function unchanged and cover it with tests
Add centerContained prop. Tests make sure new implementation does not change behavior in previous cases
Fix some edge cases that only come up when the container is larger than the image
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.
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:
_sanitizeOffset
logic into a separate function unchanged and cover it with testscenterContained
prop. Tests make sure new implementation does not change behavior in previous casesFinally,
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.