Skip to content

Commit

Permalink
fix(images): Show UI earlier for large multi-page images (#1061)
Browse files Browse the repository at this point in the history
* fix(images): Show UI earlier for large multi-page images
  • Loading branch information
mickr authored Aug 29, 2019
1 parent da531a9 commit a41eba7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
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() {
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()', () => {
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

0 comments on commit a41eba7

Please sign in to comment.