Skip to content

Commit

Permalink
fix: Only fire STACK_NEW_IMAGE event after we are certain this image …
Browse files Browse the repository at this point in the history
…will be displayed (#72)
  • Loading branch information
swederik authored Apr 12, 2022
1 parent e3c7469 commit bfb8b91
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions packages/core/src/RenderingEngine/StackViewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,13 @@ class StackViewport extends Viewport implements IStackViewport {
imageIdIndex: number,
imageId: string
) {
// Perform this check after the image has finished loading
// in case the user has already scrolled away to another image.
// In that case, do not render this image.
if (this.currentImageIdIndex !== imageIdIndex) {
return;
}

const eventDetail: EventTypes.StackNewImageEventDetail = {
image,
imageId,
Expand Down Expand Up @@ -1274,13 +1281,6 @@ class StackViewport extends Viewport implements IStackViewport {
// Todo: trigger an event to allow applications to hook into END of loading state
// Currently we use loadHandlerManagers for this

// Perform this check after the image has finished loading
// in case the user has already scrolled away to another image.
// In that case, do not render this image.
if (this.currentImageIdIndex !== imageIdIndex) {
return;
}

// Trigger the image to be drawn on the next animation frame
this.render();

Expand Down Expand Up @@ -1364,6 +1364,16 @@ class StackViewport extends Viewport implements IStackViewport {
return new Promise((resolve, reject) => {
// 1. Load the image using the Image Loader
function successCallback(image, imageIdIndex, imageId) {
// Todo: trigger an event to allow applications to hook into END of loading state
// Currently we use loadHandlerManagers for this

// Perform this check after the image has finished loading
// in case the user has already scrolled away to another image.
// In that case, do not render this image.
if (this.currentImageIdIndex !== imageIdIndex) {
return;
}

const eventDetail: EventTypes.StackNewImageEventDetail = {
image,
imageId,
Expand All @@ -1375,16 +1385,6 @@ class StackViewport extends Viewport implements IStackViewport {

this._updateActorToDisplayImageId(image);

// Todo: trigger an event to allow applications to hook into END of loading state
// Currently we use loadHandlerManagers for this

// Perform this check after the image has finished loading
// in case the user has already scrolled away to another image.
// In that case, do not render this image.
if (this.currentImageIdIndex !== imageIdIndex) {
return;
}

// Trigger the image to be drawn on the next animation frame
this.render();

Expand Down

0 comments on commit bfb8b91

Please sign in to comment.