Skip to content

Commit

Permalink
InputManager: Fix for POINTERTAP firing when cursor is moved (#13136)
Browse files Browse the repository at this point in the history
* Modify isPointerSwiping to check for moving

* format
  • Loading branch information
PolygonalSun committed Oct 19, 2022
1 parent cd0d533 commit 878b351
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions packages/dev/core/src/Inputs/scene.inputManager.ts
Expand Up @@ -89,6 +89,8 @@ export class InputManager {
private _previousPickResult: Nullable<PickingInfo> = null;
private _totalPointersPressed = 0;
private _doubleClickOccured = false;
private _isSwiping: boolean = false;
private _swipeButtonPressed: number = -1;

private _pointerOverMesh: Nullable<AbstractMesh>;

Expand Down Expand Up @@ -408,10 +410,7 @@ export class InputManager {
* @internals Boolean if delta for pointer exceeds drag movement threshold
*/
public _isPointerSwiping(): boolean {
return (
Math.abs(this._startingPointerPosition.x - this._pointerX) > InputManager.DragMovementThreshold ||
Math.abs(this._startingPointerPosition.y - this._pointerY) > InputManager.DragMovementThreshold
);
return this._isSwiping;
}

/**
Expand Down Expand Up @@ -725,6 +724,13 @@ export class InputManager {
(!scene.cameraToUseForPointers || (scene.cameraToUseForPointers.layerMask & mesh.layerMask) !== 0);
}

// Check if pointer leaves DragMovementThreshold range to determine if swipe is occurring
if (!this._isSwiping && this._swipeButtonPressed !== -1) {
this._isSwiping =
Math.abs(this._startingPointerPosition.x - this._pointerX) > InputManager.DragMovementThreshold ||
Math.abs(this._startingPointerPosition.y - this._pointerY) > InputManager.DragMovementThreshold;
}

const pickResult = scene._registeredActions > 0 ? this._pickMove((evt as IPointerEvent).pointerId) : null;
this._processPointerMove(pickResult, evt as IPointerEvent);
};
Expand All @@ -741,6 +747,10 @@ export class InputManager {

this._updatePointerPosition(evt);

if (this._swipeButtonPressed === -1) {
this._swipeButtonPressed = evt.button;
}

if (scene.preventDefaultOnPointerDown && elementToAttachTo) {
evt.preventDefault();
elementToAttachTo.focus();
Expand Down Expand Up @@ -857,6 +867,11 @@ export class InputManager {
this._processPointerUp(pickResult, evt, clickInfo);

this._previousPickResult = this._currentPickResult;

if (this._swipeButtonPressed === evt.button) {
this._isSwiping = false;
this._swipeButtonPressed = -1;
}
});
};

Expand Down

0 comments on commit 878b351

Please sign in to comment.