Skip to content

Commit

Permalink
fix: Call ScrollBox scroll listener when dragging content (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
CatchABus authored Aug 22, 2024
1 parent 00eac5b commit 394f960
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/ScrollBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ export class ScrollBox extends Container
{
if (!this.isDragging) return;

const isVertical: boolean = this.options.type !== 'horizontal';
const touchPoint = this.worldTransform.applyInverse(e.global);

if (this.dragStarTouchPoint)
Expand Down Expand Up @@ -430,9 +431,10 @@ export class ScrollBox extends Container
if (this.pressedChild)
{
this.revertClick(this.pressedChild);

this.pressedChild = null;
}

this.onScroll?.emit(isVertical ? this.scrollY : this.scrollX);
});

document.addEventListener('wheel', this.onMouseScrollBinding, true);
Expand Down Expand Up @@ -570,9 +572,6 @@ export class ScrollBox extends Container

protected onMouseScroll(event: WheelEvent): void
{
const isVertical: boolean = this.options.type !== 'horizontal';
const oldScrollPos = isVertical ? this.scrollY : this.scrollX;

if (!this.isOver && !this.options.globalScroll) return;

this.renderAllItems();
Expand All @@ -597,6 +596,8 @@ export class ScrollBox extends Container

this._trackpad.xAxis.value = Math.min(max, Math.max(min, targetPos));
}

this.onScroll?.emit(this._trackpad.xAxis.value);
}
else if (typeof event.deltaY !== 'undefined')
{
Expand All @@ -613,16 +614,11 @@ export class ScrollBox extends Container

this._trackpad.yAxis.value = Math.min(max, Math.max(min, targetPos));
}

this.onScroll?.emit(this._trackpad.yAxis.value);
}

this.stopRenderHiddenItems();

const newScrollPos = isVertical ? this.scrollY : this.scrollX;

if (newScrollPos !== oldScrollPos)
{
this.onScroll?.emit(newScrollPos);
}
}

/** Makes it scroll down to the last element. */
Expand Down

0 comments on commit 394f960

Please sign in to comment.