-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Image block: Fix responsive sizing in lightbox #51823
Conversation
Size Change: +295 B (0%) Total Size: 1.44 MB
ℹ️ View Unchanged
|
Flaky tests detected in 8eb60bbac3d8ed75cb3282aab9925d094e0c6b7b. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5402239935
|
be83100
to
b4a3c1d
Compare
b39b820
to
b61f3ce
Compare
It appears the close button is not always visible on Android, or sometimes it appears too closely to the top corner of the screen. Likely this can be resolved by using the Other than that, I believe this PR is ready for feedback on the approach and any suggestions. |
b61f3ce
to
958a40a
Compare
After more testing, it turns out this was an issue related to the WP Twenty Twenty Two theme, which has horizontal overflow on some mobile Android devices. After switching to Twenty Twenty Three, the issue with the close button disappeared. Even so, I added the I also added a couple of other miscellaneous fixes to improve the lightbox code, namely: With that, I believe this PR is good to go 👍 |
958a40a
to
a0d2640
Compare
On mobile, the address bar is sometimes visible in browsers, which the CSS vh (viewport height) value does not account for. This causes calculations based on vh to render incorrectly if the address bar is ever visible - in this case, placing the lightbox image off center. To address this, I changed the lightbox calculations to be based on window.innerHeight and window.innerWidth instead.
This reverts commit a4c9a22ccd17fc92f5dd99796b52605654ce82e9.
8eb60bb
to
f1971e3
Compare
targetWidth = | ||
imgDom.naturalWidth * ( targetHeight / imgDom.naturalHeight ); | ||
( targetHeight * imgDom.naturalWidth ) / imgDom.naturalHeight; |
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.
Could have imgDom.naturalWidth
, imgDom.naturalHeight
, containerInnerHeight
or targetHeight
0 as value?
If they are 0 or NaN in any moment, they will cause a warning/error.
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.
If they are 0 or NaN in any moment, they will cause a warning/error.
Thanks for bringing this up! The only way I could see this happening is if a user inserts a broken external image with an incorrect URL, in which case other parts of WordPress also break. If an image is not fully loaded, it will return 0 for the naturalWidth
and naturalHeight
, but since we wait until the image is fully loaded to activate this part of the code, I don't believe that's currently an issue.
We can revisit this if any issues do arise in the future or if we revise the functionality, but for the moment I don't think handling this should be a blocker for this PR 👍
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.
What happens then if the user inserts a working external image, and then, suppose in couple of months, the external site closes and all the images are gone?
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.
Double checked this and we get some PHP errors due to getimagesize()
that can actually likely be circumvented. I've captured the getimagesize()
in an issue and the implementation is going to change soon, so I can handle this issue then.
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.
Ok I opened a pull request that fixes this 👍
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.
It works as described, feel free to take a look at the comment regarding unexpected warnings and should be good to go!
What?
This revises the logic for calculating image dimensions in the lightbox, as well as adds some styles, because the images were getting stretched in some cases.
This was most pronounced on mobile, but it was visible on desktop as well.
Why?
Addresses #51556
The lightbox images should be scaled properly at all resolutions.
How?
It calculates the inner width of the parent container based on the padding, then compares the aspect ratio of the image to the inner container to determine on which axis to resize the image.
Testing Instructions
Please test a horizontal image, a vertical image, and a square image, at various resolutions, on mobile as well as desktop, and in different browsers.
Testing Instructions for Keyboard
N/A
Screenshots
Before
246260204-7de47f54-03d3-46a9-93c3-3a2dbd799a77.mp4
After
lightbox-test-responsiveness.mp4