-
Notifications
You must be signed in to change notification settings - Fork 116
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
Fix: Image viewer flickering in IE11 during reset zoom #594
Conversation
Verified that @DanDeMicco has signed the CLA. Thanks for the pull request! |
src/lib/viewers/image/ImageViewer.js
Outdated
@@ -126,12 +126,26 @@ class ImageViewer extends ImageBaseViewer { | |||
zoom(type) { | |||
let newWidth; | |||
let newHeight; | |||
const imageCurrentDimensions = this.imageEl.getBoundingClientRect(); // Getting bounding rect does not ignore transforms / rotates | |||
let imageCurrentDimensions; | |||
if (type === 'reset') { |
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.
Can we keep this in the switch statement? You can set imageCurrentDimensions
here and then update it in the switch statement if we are resetting. It feels a little weird to check for the 'reset' case and then switch on type right after.
src/lib/viewers/image/ImageViewer.js
Outdated
* @param {number} [height] - The height in px | ||
* @return {boolean} true if the width will be modified instead of height | ||
*/ | ||
getModifyWidthInsteadOfHeight(width, height) { |
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.
Why not go with something like isLandscape()
, since we're essentially checking whether or not the width is greater than the height? Also, we could reduce this to return width >= height
. Were there any other reasons behind using aspect ratio?
Note: We may already have an isLandscape()
method hiding somewhere
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.
Good point, the CR was just moving around code but I don't see the aspect ratio being used anywhere.
As for the isLandscape method hiding somewhere, I was not able to find one, so just incorporated your comments and renamed the method
src/lib/viewers/image/ImageViewer.js
Outdated
if (modifyWidthInsteadOfHeight) { | ||
newWidth = type === 'in' ? width * IMAGE_ZOOM_SCALE : width / IMAGE_ZOOM_SCALE; | ||
} else { | ||
newHeight = type === 'in' ? height * IMAGE_ZOOM_SCALE : (newHeight = height / IMAGE_ZOOM_SCALE); |
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.
I think you can remove the assignment as the last component of the ternary.
newHeight = type === 'in' ? height * IMAGE_ZOOM_SCALE : height / IMAGE_ZOOM_SCALE;
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.
Good catch, that was what I meant to put there to match the newWidth expression
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's up to you, but if there's anything you can abstract away, inside of zoom()
to make that function smaller/easier to read, that'd be cool!
src/lib/viewers/image/ImageViewer.js
Outdated
@@ -116,6 +116,21 @@ class ImageViewer extends ImageBaseViewer { | |||
this.setScale(this.imageEl.offsetwidth, this.imageEl.offsetHeight); | |||
} | |||
|
|||
/** | |||
* Getter for modifyWidthInsteadOfHeight which will be used in zoom |
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.
Update docs to not refer to modifyWidthInsteadOfHeight
src/lib/viewers/image/ImageViewer.js
Outdated
* @private | ||
* @param {number} [width] - The width in px | ||
* @param {number} [height] - The height in px | ||
* @return {boolean} true if the width will be modified instead of height |
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.
true if image is landscape layout, or something like that
src/lib/viewers/image/ImageViewer.js
Outdated
* @return {boolean} true if the width will be modified instead of height | ||
*/ | ||
isLandscape(width, height) { | ||
// For multi page tifs, we always modify the width, since its essentially a DIV and not IMG tag. |
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.
I'd say we can remove these two comment lines
@@ -521,4 +543,16 @@ describe('lib/viewers/image/ImageViewer', () => { | |||
}); | |||
}); | |||
}); | |||
|
|||
describe('getModifyWidthInsteadOfHeight()', () => { |
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.
update test name to isLandscape()
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.
Just make sure to test this super thoroughly on all browsers/mobile devices :) Zooming/scaling of images has always been full of edge cases
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.
Great refactor! If it's good with annotations on mobile and desktop, feel free to merge
81ac232
to
bed3312
Compare
The old 'reset' case set the image width & height, then recursively called zoom, which caused the image to be resized twice and thus flickered in IE11.
Also, has a minor additional bugfix in which the image was rendered at the incorrect size by default, thus when resetting on a freshly rendered image it would slightly resize. This was due to use of clientHeight instead of offsetHeight which does not include the scrollbar (which may be on initial load)