Skip to content

Add prop zoomAlignmentY to control zoomed image vertical alignment relative to the viewport #883

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

alexrah
Copy link

@alexrah alexrah commented May 19, 2025

Description

This pull request add a prop to and component zoomAlignmentY
this props allow to control the zoomed image vertical alignment relative to the viewport; it defaults to center to keep the standard behavior consistent, but add also the option top to align the image to the viewport top
This is especially useful when used together with prop ZoomContent and showing some additional content along the image when zoomed, for instance an extended image description: aligning the zoomed image to top leave a lot more viewport space available

Testing

  1. Create a or wrapped element
  2. add the prop <Controlled zoomAlignmentY='top'>[...]</ Controlled>
  3. Click on any image to zoom
  4. Image should be aligned to viewport's top edge
  5. to test the defaults, just create an element normallly without setting zoomAlignmentY and it should align to center as asual

Copy link
Owner

@rpearce rpearce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting your work and using this tool. There are some things for you clean up in this pull request, and I'll think about if it's something I want to support.

README.md Outdated
@@ -2,6 +2,10 @@

[![npm version](https://img.shields.io/npm/v/react-medium-image-zoom.svg)](https://www.npmjs.com/package/react-medium-image-zoom) [![react-medium-image-zoom bundlejs badge](https://deno.bundlejs.com/?q=react-medium-image-zoom&badge=&config={%22esbuild%22:{%22external%22:[%22react%22,%22react-dom%22]}})](https://bundlejs.com/?q=react-medium-image-zoom) [![npm downloads](https://img.shields.io/npm/dm/react-medium-image-zoom.svg)](https://www.npmjs.com/package/react-medium-image-zoom) [![All Contributors](https://img.shields.io/badge/all_contributors-89-orange.svg)](#contributors-)

## Disclaimer
this package is a fork of [react-medium-image-zoom](https://github.com/rpearce/react-medium-image-zoom/) with added functionality waiting to be merged in upstream.
see pull requests for more details: https://github.com/rpearce/react-medium-image-zoom/pull/883
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be in the PR

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this wasn't intentional. I needed to publish this ASAP while waiting but it wasn't intended for the pull request, it's been removed.

package.json Outdated
@@ -35,7 +38,8 @@
"Yida Zhang <[email protected]>",
"eych",
"tshmieldev",
"David Edler (https://github.com/edlerd)"
"David Edler (https://github.com/edlerd)",
"Alessandro Stoppato <[email protected]>"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think anything in this file should be in the PR

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this wasn't intentional. I needed to publish this ASAP while waiting but it wasn't intended for the pull request, it's been removed.

@@ -88,6 +89,7 @@ interface ControlledDefaultProps {
swipeToUnzoomThreshold: number
wrapElement: 'div' | 'span'
zoomMargin: number
zoomAlignmentY: 'center' | 'top'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for not including 'bottom'?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I would, alphabetically, put this before zoomMargin here and the other places in this file.

Copy link
Author

@alexrah alexrah May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the bottom value for zoomAlignmentY
there is an issue though, shared with the default center alignment: when zoomed image is wrapped inside a container having position: relative and a height which is not the same as viewport's, the position of the zoomed image is wrong.
It can be addressed by setting the translate property based on the first parent with position: relative instead of window.innerHeight but I don't see a way in the current implementation to get the zoomed image parent element in getStyleModalImg()

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have a look when I can. I don't have a lot of time to work on this, but a little bit here and there.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand. Anyway the issue is not related to the new functionality and should be fixed in another pull request.
I'll try to look into the stories when I have time to update that as well.
Hopefully it can be merged then.

Copy link
Owner

@rpearce rpearce May 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's less a matter of the code changes and more a matter of: "Do I want to support this behavior forever?"

Other things I need to consider:

  • Is there a different API to provide?
  • What if somebody wants to move it to a predefined position on both the Y and X axes?
  • Is any of this something that this library should do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants