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(images): Show UI earlier for large multi-page images #1061

Merged
merged 6 commits into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/lib/viewers/image/MultiImageViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class MultiImageViewer extends ImageBaseViewer {
this.handlePageChangeFromScroll = this.handlePageChangeFromScroll.bind(this);
this.handleMultiImageDownloadError = this.handleMultiImageDownloadError.bind(this);
this.handleAssetAndRepLoad = this.handleAssetAndRepLoad.bind(this);
this.finishLoading = this.finishLoading.bind(this);
}

/**
Expand Down Expand Up @@ -90,6 +91,17 @@ class MultiImageViewer extends ImageBaseViewer {
.catch(this.handleAssetError);
}

/**
* Handles the load event for the first image.
*
* @return {void}
*/

finishLoading() {
super.finishLoading();
this.setOriginalImageSizes();
}

/**
* Loads the multipart image for viewing
*
Expand Down Expand Up @@ -151,8 +163,14 @@ class MultiImageViewer extends ImageBaseViewer {
this.singleImageEls[index].src = imageUrl;
}

/** @inheritdoc */
setOriginalImageSize() {
/**
* Sets the original image width and height on the img element. Can be removed when
* naturalHeight and naturalWidth attributes work correctly in IE 11.
*
* @protected
* @return {Promise} A promise that is resolved if the original image dimensions were set.
*/
setOriginalImageSizes() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any tests needed?

const promises = [];

this.singleImageEls.forEach(imageEl => {
Expand Down
8 changes: 4 additions & 4 deletions src/lib/viewers/image/__tests__/MultiImageViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ describe('lib/viewers/image/MultiImageViewer', () => {
.catch(() => {});
});

it('should make the images invisible', () => {
it('should ensure load timer is started', () => {
sandbox.stub(multiImage, 'startLoadTimer');
return multiImage
.load('file/100/content/{page}.png')
Expand Down Expand Up @@ -232,19 +232,19 @@ describe('lib/viewers/image/MultiImageViewer', () => {
});
});

describe('setOriginalImageSize()', () => {
describe('setOriginalImageSizes()', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should the child tests now invoke multiImage.setOriginalImageSizes(), instead?

beforeEach(() => {
multiImage.singleImageEls = [stubs.singleImageEl, stubs.singleImageEl, stubs.singleImageEl];
});

it('should return a promise', () => {
const promise = multiImage.setOriginalImageSize();
const promise = multiImage.setOriginalImageSizes();
expect(promise).to.be.a('Promise');
});

it('should return a promise that resolves after each image has a proper size', done => {
// We've overridden super.setOriginalImageSize() to resolve immediately
multiImage.setOriginalImageSize().then(() => {
multiImage.setOriginalImageSizes().then(() => {
done();
});
});
Expand Down