Skip to content

Commit

Permalink
fix scroll bug
Browse files Browse the repository at this point in the history
  • Loading branch information
BunkFME committed Apr 15, 2024
1 parent bf3d339 commit dc7f748
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
11 changes: 8 additions & 3 deletions packages/core/src/RenderingEngine/StackViewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2445,8 +2445,9 @@ class StackViewport extends Viewport implements IStackViewport, IImagesLoader {
/**
* Loads the image based on the provided imageIdIndex
* @param imageIdIndex - number represents imageId index
* @param overwriteScrollIndex - can be used to also set the start position of scroll() to this index
*/
private async _setImageIdIndex(imageIdIndex: number): Promise<string> {
private async _setImageIdIndex(imageIdIndex: number, overwriteScrollIndex: boolean = false): Promise<string> {
if (imageIdIndex >= this.imageIds.length) {
throw new Error(
`ImageIdIndex provided ${imageIdIndex} is invalid, the stack only has ${this.imageIds.length} elements`
Expand All @@ -2455,6 +2456,9 @@ class StackViewport extends Viewport implements IStackViewport, IImagesLoader {

// Update the state of the viewport to the new imageIdIndex;
this.currentImageIdIndex = imageIdIndex;
if (overwriteScrollIndex) {
this.targetImageIdIndex = this.currentImageIdIndex;
}
this.hasPixelSpacing = true;
this.viewportStatus = ViewportStatus.PRE_RENDER;

Expand Down Expand Up @@ -2583,8 +2587,9 @@ class StackViewport extends Viewport implements IStackViewport, IImagesLoader {
*
* @param imageIdIndex - number represents imageId index in the list of
* provided imageIds in setStack
* @param overwriteScrollIndex - can be used to also set the start position of scroll() to this index
*/
public setImageIdIndex(imageIdIndex: number): Promise<string> {
public setImageIdIndex(imageIdIndex: number, overwriteScrollIndex: boolean = false): Promise<string> {
this._throwIfDestroyed();

// If we are already on this imageId index, stop here
Expand All @@ -2593,7 +2598,7 @@ class StackViewport extends Viewport implements IStackViewport, IImagesLoader {
}

// Otherwise, get the imageId and attempt to display it
const imageIdPromise = this._setImageIdIndex(imageIdIndex);
const imageIdPromise = this._setImageIdIndex(imageIdIndex, overwriteScrollIndex);

return imageIdPromise;
}
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/types/IStackViewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,10 @@ export default interface IStackViewport extends IViewport {
* Loads the image based on the provided imageIdIndex. It is an Async function which
* returns a promise that resolves to the imageId.
*/
setImageIdIndex(imageIdIndex: number): Promise<string>;
setImageIdIndex(
imageIdIndex: number,
overwriteScrollIndex: boolean
): Promise<string>;
/**
* Calibrates the image with new metadata that has been added for imageId. To calibrate
* a viewport, you should add your calibration data manually to
Expand Down

0 comments on commit dc7f748

Please sign in to comment.