From 46e5714bc0f99dbc230665c26eec881e2843f4a9 Mon Sep 17 00:00:00 2001 From: Dmytro Soldatov Date: Wed, 31 Jan 2024 00:31:33 +0200 Subject: [PATCH] fix issue --- src/ScrollBox.ts | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/src/ScrollBox.ts b/src/ScrollBox.ts index 6a01a3df..aacdf4b6 100644 --- a/src/ScrollBox.ts +++ b/src/ScrollBox.ts @@ -1,4 +1,4 @@ -import { ColorSource, Ticker, utils } from '@pixi/core'; +import { ColorSource, Ticker, utils, Point } from '@pixi/core'; import { Container, DisplayObject, IDestroyOptions } from '@pixi/display'; import { EventMode, FederatedPointerEvent } from '@pixi/events'; import { Graphics } from '@pixi/graphics'; @@ -19,6 +19,7 @@ export type ScrollBoxOptions = { horPadding?: number; padding?: number; disableEasing?: boolean; + dragTrashHold?: number; }; /** @@ -66,6 +67,7 @@ export class ScrollBox extends Container protected options: ScrollBoxOptions; protected stopRenderHiddenItemsTimeout!: NodeJS.Timeout; protected onMouseScrollBinding = this.onMouseScroll.bind(this); + protected dragStarTouchPoint: Point; /** * @param options @@ -314,9 +316,9 @@ export class ScrollBox extends Container this.renderAllItems(); this.isDragging = 1; - const touchPoint = this.worldTransform.applyInverse(e.global); + this.dragStarTouchPoint = this.worldTransform.applyInverse(e.global); - this._trackpad.pointerDown(touchPoint); + this._trackpad.pointerDown(this.dragStarTouchPoint); const listTouchPoint = this.list.worldTransform.applyInverse(e.global); @@ -356,11 +358,37 @@ export class ScrollBox extends Container this.on('globalpointermove', (e: FederatedPointerEvent) => { + if (!this.isDragging) return; + const touchPoint = this.worldTransform.applyInverse(e.global); - this._trackpad.pointerMove(touchPoint); + if (this.dragStarTouchPoint) + { + const dragTrashHold = this.options.dragTrashHold ?? 10; - if (!this.isDragging) return; + if (this.options.type === 'horizontal') + { + const xDist = touchPoint.x - this.dragStarTouchPoint.x; + + if (Math.abs(xDist) > dragTrashHold) + { + this.isDragging = 2; + } + } + else + { + const yDist = touchPoint.y - this.dragStarTouchPoint.y; + + if (Math.abs(yDist) > dragTrashHold) + { + this.isDragging = 2; + } + } + } + + if (this.dragStarTouchPoint && this.isDragging !== 2) return; + + this._trackpad.pointerMove(touchPoint); if (this.pressedChild) {