Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

100 pointertap event doesn't work for ScrollBox items on mobile phone #129

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions src/ScrollBox.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -19,6 +19,7 @@ export type ScrollBoxOptions = {
horPadding?: number;
padding?: number;
disableEasing?: boolean;
dragTrashHold?: number;
};

/**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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)
{
Expand Down
Loading