Skip to content
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

Merged
merged 16 commits into from
Jan 26, 2018

Conversation

DanDeMicco
Copy link
Contributor

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)

@boxcla
Copy link

boxcla commented Jan 19, 2018

Verified that @DanDeMicco has signed the CLA. Thanks for the pull request!

@@ -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') {
Copy link
Contributor

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.

* @param {number} [height] - The height in px
* @return {boolean} true if the width will be modified instead of height
*/
getModifyWidthInsteadOfHeight(width, height) {
Copy link
Contributor

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

Copy link
Contributor Author

@DanDeMicco DanDeMicco Jan 22, 2018

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

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);
Copy link
Contributor

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;

Copy link
Contributor Author

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

Copy link
Contributor

@JustinHoldstock JustinHoldstock left a 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!

@@ -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
Copy link
Contributor

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

* @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
Copy link
Contributor

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

* @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.
Copy link
Contributor

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()', () => {
Copy link
Contributor

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()

Copy link
Contributor

@pramodsum pramodsum left a 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

Copy link
Contributor

@JustinHoldstock JustinHoldstock left a 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

@DanDeMicco DanDeMicco force-pushed the master branch 2 times, most recently from 81ac232 to bed3312 Compare January 26, 2018 00:50
@DanDeMicco DanDeMicco merged commit d43094f into box:master Jan 26, 2018
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.

7 participants