From 394f960fba04d9ea984d65f230ee61ce1dc86ae8 Mon Sep 17 00:00:00 2001 From: Dimitris-Rafail Katsampas Date: Thu, 22 Aug 2024 16:04:02 +0300 Subject: [PATCH] fix: Call ScrollBox scroll listener when dragging content (#192) --- src/ScrollBox.ts | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/ScrollBox.ts b/src/ScrollBox.ts index 14dd1b9..15df482 100644 --- a/src/ScrollBox.ts +++ b/src/ScrollBox.ts @@ -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) @@ -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); @@ -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(); @@ -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') { @@ -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. */