-
Notifications
You must be signed in to change notification settings - Fork 113
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
Changes from 1 commit
92f56a4
7794922
9ad59fd
a85ad5a
555cc0e
e68d615
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ class ImageBaseViewer extends BaseViewer { | |
this.handleMouseUp = this.handleMouseUp.bind(this); | ||
this.cancelDragEvent = this.cancelDragEvent.bind(this); | ||
this.finishLoading = this.finishLoading.bind(this); | ||
this.showUi = this.showUi.bind(this); | ||
|
||
if (this.isMobile) { | ||
if (Browser.isIOS()) { | ||
|
@@ -64,6 +65,21 @@ class ImageBaseViewer extends BaseViewer { | |
super.destroy(); | ||
} | ||
|
||
/** | ||
* Shows controls for images and removes loading indicator | ||
* | ||
* @return {void} | ||
*/ | ||
showUi() { | ||
if (!this.isLoaded()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make this a guard clause to avoid the nested logic? |
||
this.loadUI(); | ||
this.zoom(); | ||
this.imageEl.classList.remove(CLASS_INVISIBLE); | ||
this.loaded = true; | ||
this.emit(VIEWER_EVENT.load); | ||
} | ||
} | ||
|
||
/** | ||
* Finishes loading the images. | ||
* | ||
|
@@ -76,12 +92,7 @@ class ImageBaseViewer extends BaseViewer { | |
|
||
const loadOriginalDimensions = this.setOriginalImageSize(this.imageEl); | ||
loadOriginalDimensions.then(() => { | ||
this.loadUI(); | ||
this.zoom(); | ||
|
||
this.imageEl.classList.remove(CLASS_INVISIBLE); | ||
this.loaded = true; | ||
this.emit(VIEWER_EVENT.load); | ||
this.showUi(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this need to be a separate method? It doesn't seem like the logical flow has changed and we don't have a
|
||
}); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ const PADDING_BUFFER = 100; | |
const CSS_CLASS_IMAGE = 'bp-images'; | ||
const CSS_CLASS_IMAGE_WRAPPER = 'bp-images-wrapper'; | ||
const ZOOM_UPDATE_PAN_DELAY = 50; | ||
const MULTI_PAGE_LOAD_LIMIT = 10; | ||
|
||
class MultiImageViewer extends ImageBaseViewer { | ||
/** @property {Image[]} - List of images rendered sequentially */ | ||
|
@@ -23,6 +24,7 @@ class MultiImageViewer extends ImageBaseViewer { | |
this.handlePageChangeFromScroll = this.handlePageChangeFromScroll.bind(this); | ||
this.handleMultiImageDownloadError = this.handleMultiImageDownloadError.bind(this); | ||
this.handleAssetAndRepLoad = this.handleAssetAndRepLoad.bind(this); | ||
this.handleFirstImageLoad = this.handleFirstImageLoad.bind(this); | ||
} | ||
|
||
/** | ||
|
@@ -90,6 +92,22 @@ class MultiImageViewer extends ImageBaseViewer { | |
.catch(this.handleAssetError); | ||
} | ||
|
||
/** | ||
* Handles the load event for the first image. | ||
* | ||
* @return {void} Promise to load bunch of images | ||
*/ | ||
|
||
handleFirstImageLoad() { | ||
if (this.singleImageEls.length > MULTI_PAGE_LOAD_LIMIT) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this limit needed or can we always load the first page as soon as it's ready? Is there a penalty to doing so? If not, it seems like we can remove this entire block and call |
||
super.setOriginalImageSize(this.imageEl).then(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should |
||
this.showUi(); | ||
}); | ||
} | ||
|
||
this.finishLoading(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be in an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I don't believe so since there is more work for |
||
} | ||
|
||
/** | ||
* Loads the multipart image for viewing | ||
* | ||
|
@@ -288,7 +306,7 @@ class MultiImageViewer extends ImageBaseViewer { | |
*/ | ||
bindImageListeners(index) { | ||
if (index === 0) { | ||
this.singleImageEls[index].addEventListener('load', this.finishLoading); | ||
this.singleImageEls[index].addEventListener('load', this.handleFirstImageLoad); | ||
} | ||
|
||
this.singleImageEls[index].addEventListener('error', this.handleMultiImageDownloadError); | ||
|
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.
showUI
?