From 000749a1d273c621b3259bcbba3bfc66de1d0480 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bert?= Date: Fri, 6 Oct 2023 10:50:19 +0200 Subject: [PATCH 01/20] Get info about ScrollView --- src/handlers/NativeViewGestureHandler.ts | 3 +++ src/handlers/createNativeWrapper.tsx | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/handlers/NativeViewGestureHandler.ts b/src/handlers/NativeViewGestureHandler.ts index acba7908a5..230c7758c2 100644 --- a/src/handlers/NativeViewGestureHandler.ts +++ b/src/handlers/NativeViewGestureHandler.ts @@ -7,6 +7,7 @@ import { export const nativeViewGestureHandlerProps = [ 'shouldActivateOnStart', 'disallowInterruption', + 'isScrollView', ] as const; export interface NativeViewGestureConfig { @@ -23,6 +24,8 @@ export interface NativeViewGestureConfig { * `NativeViewGestureHandler` receives an `ACTIVE` state event. */ disallowInterruption?: boolean; + + isScrollView?: boolean; } export interface NativeViewGestureHandlerProps diff --git a/src/handlers/createNativeWrapper.tsx b/src/handlers/createNativeWrapper.tsx index 8dfc32c2b9..c82266527d 100644 --- a/src/handlers/createNativeWrapper.tsx +++ b/src/handlers/createNativeWrapper.tsx @@ -58,9 +58,11 @@ export default function createNativeWrapper

( }, [_ref, _gestureHandlerRef] ); + return ( From e4b09cb0f8f07a3fd61f257cca02bfdbff87ced8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bert?= Date: Wed, 11 Oct 2023 14:41:15 +0200 Subject: [PATCH 02/20] Simplify if --- src/web/tools/GestureHandlerOrchestrator.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/web/tools/GestureHandlerOrchestrator.ts b/src/web/tools/GestureHandlerOrchestrator.ts index d0833f6481..78a7085a60 100644 --- a/src/web/tools/GestureHandlerOrchestrator.ts +++ b/src/web/tools/GestureHandlerOrchestrator.ts @@ -287,10 +287,7 @@ export default class GestureHandlerOrchestrator { return false; } - if ( - handler !== otherHandler && - (handler.isAwaiting() || handler.getState() === State.ACTIVE) - ) { + if (handler.isAwaiting() || handler.getState() === State.ACTIVE) { // For now it always returns false return handler.shouldBeCancelledByOther(otherHandler); } From 756505d89a88372cc100d829151038bd6682955e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bert?= Date: Thu, 12 Oct 2023 15:24:44 +0200 Subject: [PATCH 03/20] Remove touchAction --- src/web/tools/GestureHandlerWebDelegate.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/web/tools/GestureHandlerWebDelegate.ts b/src/web/tools/GestureHandlerWebDelegate.ts index 39d2052a1b..d47b29ddea 100644 --- a/src/web/tools/GestureHandlerWebDelegate.ts +++ b/src/web/tools/GestureHandlerWebDelegate.ts @@ -31,10 +31,6 @@ export class GestureHandlerWebDelegate this.gestureHandler = handler; this.view = findNodeHandle(viewRef) as unknown as HTMLElement; - this.view.style['touchAction'] = 'none'; - //@ts-ignore This one disables default events on Safari - this.view.style['WebkitTouchCallout'] = 'none'; - const config = handler.getConfig(); if (!config.userSelect) { From 3298f86edfcf2fac5e7edd326e76fc3903282f64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bert?= Date: Thu, 12 Oct 2023 15:26:24 +0200 Subject: [PATCH 04/20] Implement shouldHandlerBeCancelledBy --- src/web/tools/InteractionManager.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/web/tools/InteractionManager.ts b/src/web/tools/InteractionManager.ts index 0987428f1c..0bce4a44de 100644 --- a/src/web/tools/InteractionManager.ts +++ b/src/web/tools/InteractionManager.ts @@ -1,5 +1,7 @@ +import NativeViewGestureHandler from '../handlers/NativeViewGestureHandler'; import GestureHandler from '../handlers/GestureHandler'; import { Config, Handler } from '../interfaces'; +import { State } from '../../State'; export default class InteractionManager { private static instance: InteractionManager; @@ -97,10 +99,14 @@ export default class InteractionManager { public shouldHandlerBeCancelledBy( _handler: GestureHandler, - _otherHandler: GestureHandler + otherHandler: GestureHandler ): boolean { - //TODO: Implement logic - return false; + const shouldBeCancelledByScrollView = + otherHandler instanceof NativeViewGestureHandler && + otherHandler.getLastSentState() === State.ACTIVE && + otherHandler.getState() === State.ACTIVE; + + return shouldBeCancelledByScrollView; } public dropRelationsForHandlerWithTag(handlerTag: number): void { From 2f77ae49c5e84bc7477ee7c0f7a123c40ef21727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bert?= Date: Thu, 12 Oct 2023 15:26:51 +0200 Subject: [PATCH 05/20] add getLastSentState --- src/web/handlers/GestureHandler.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/web/handlers/GestureHandler.ts b/src/web/handlers/GestureHandler.ts index ac6a0e1813..c0985eb810 100644 --- a/src/web/handlers/GestureHandler.ts +++ b/src/web/handlers/GestureHandler.ts @@ -770,6 +770,10 @@ export default abstract class GestureHandler { return this.currentState; } + public getLastSentState(): State | null { + return this.lastSentState; + } + public isEnabled(): boolean { return this.enabled; } From c5a953fc2a0520327597dea7d0ca70f33f746e50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bert?= Date: Thu, 12 Oct 2023 16:05:10 +0200 Subject: [PATCH 06/20] remove isScrollView --- src/handlers/NativeViewGestureHandler.ts | 3 --- src/handlers/createNativeWrapper.tsx | 2 -- 2 files changed, 5 deletions(-) diff --git a/src/handlers/NativeViewGestureHandler.ts b/src/handlers/NativeViewGestureHandler.ts index 230c7758c2..acba7908a5 100644 --- a/src/handlers/NativeViewGestureHandler.ts +++ b/src/handlers/NativeViewGestureHandler.ts @@ -7,7 +7,6 @@ import { export const nativeViewGestureHandlerProps = [ 'shouldActivateOnStart', 'disallowInterruption', - 'isScrollView', ] as const; export interface NativeViewGestureConfig { @@ -24,8 +23,6 @@ export interface NativeViewGestureConfig { * `NativeViewGestureHandler` receives an `ACTIVE` state event. */ disallowInterruption?: boolean; - - isScrollView?: boolean; } export interface NativeViewGestureHandlerProps diff --git a/src/handlers/createNativeWrapper.tsx b/src/handlers/createNativeWrapper.tsx index c82266527d..8dfc32c2b9 100644 --- a/src/handlers/createNativeWrapper.tsx +++ b/src/handlers/createNativeWrapper.tsx @@ -58,11 +58,9 @@ export default function createNativeWrapper

( }, [_ref, _gestureHandlerRef] ); - return ( From 922622dad932a88ec1c94e1b19fd0ced78cec7d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bert?= Date: Thu, 12 Oct 2023 16:22:20 +0200 Subject: [PATCH 07/20] add preventDefault to Pan --- src/web/handlers/GestureHandler.ts | 76 ++++++++++----- src/web/handlers/PanGestureHandler.ts | 25 ++++- src/web/tools/EventManager.ts | 130 +++++++++++++++++++++----- src/web/tools/TouchEventManager.ts | 8 +- 4 files changed, 188 insertions(+), 51 deletions(-) diff --git a/src/web/handlers/GestureHandler.ts b/src/web/handlers/GestureHandler.ts index c0985eb810..d77cd5b2bd 100644 --- a/src/web/handlers/GestureHandler.ts +++ b/src/web/handlers/GestureHandler.ts @@ -272,42 +272,60 @@ export default abstract class GestureHandler { // Event actions // - protected onPointerDown(event: AdaptedEvent): void { + protected onPointerDown( + adaptedEvent: AdaptedEvent, + _originalEvent?: TouchEvent | PointerEvent + ): void { GestureHandlerOrchestrator.getInstance().recordHandlerIfNotPresent(this); - this.pointerType = event.pointerType; + this.pointerType = adaptedEvent.pointerType; if (this.pointerType === PointerType.TOUCH) { GestureHandlerOrchestrator.getInstance().cancelMouseAndPenGestures(this); } if (this.config.needsPointerData) { - this.sendTouchEvent(event); + this.sendTouchEvent(adaptedEvent); } } // Adding another pointer to existing ones - protected onPointerAdd(event: AdaptedEvent): void { + protected onPointerAdd( + adaptedEvent: AdaptedEvent, + _originalEvent?: TouchEvent | PointerEvent + ): void { if (this.config.needsPointerData) { - this.sendTouchEvent(event); + this.sendTouchEvent(adaptedEvent); } } - protected onPointerUp(event: AdaptedEvent): void { + protected onPointerUp( + adaptedEvent: AdaptedEvent, + _originalEvent?: TouchEvent | PointerEvent + ): void { if (this.config.needsPointerData) { - this.sendTouchEvent(event); + this.sendTouchEvent(adaptedEvent); } } // Removing pointer, when there is more than one pointers - protected onPointerRemove(event: AdaptedEvent): void { + protected onPointerRemove( + adaptedEvent: AdaptedEvent, + _originalEvent?: TouchEvent | PointerEvent + ): void { if (this.config.needsPointerData) { - this.sendTouchEvent(event); + this.sendTouchEvent(adaptedEvent); } } - protected onPointerMove(event: AdaptedEvent): void { + protected onPointerMove( + adaptedEvent: AdaptedEvent, + _originalEvent?: TouchEvent | PointerEvent + ): void { this.tryToSendMoveEvent(false); if (this.config.needsPointerData) { - this.sendTouchEvent(event); + this.sendTouchEvent(adaptedEvent); } } - protected onPointerLeave(event: AdaptedEvent): void { + protected onPointerLeave( + adaptedEvent: AdaptedEvent, + _originalEvent?: TouchEvent | PointerEvent + ): void { if (this.shouldCancellWhenOutside) { switch (this.currentState) { case State.ACTIVE: @@ -321,34 +339,50 @@ export default abstract class GestureHandler { } if (this.config.needsPointerData) { - this.sendTouchEvent(event); + this.sendTouchEvent(adaptedEvent); } } - protected onPointerEnter(event: AdaptedEvent): void { + protected onPointerEnter( + adaptedEvent: AdaptedEvent, + _originalEvent?: TouchEvent | PointerEvent + ): void { if (this.config.needsPointerData) { - this.sendTouchEvent(event); + this.sendTouchEvent(adaptedEvent); } } - protected onPointerCancel(event: AdaptedEvent): void { + protected onPointerCancel( + adaptedEvent: AdaptedEvent, + _originalEvent?: TouchEvent | PointerEvent + ): void { if (this.config.needsPointerData) { - this.sendTouchEvent(event); + this.sendTouchEvent(adaptedEvent); } this.cancel(); this.reset(); } - protected onPointerOutOfBounds(event: AdaptedEvent): void { + protected onPointerOutOfBounds( + adaptedEvent: AdaptedEvent, + _originalEvent?: TouchEvent | PointerEvent + ): void { this.tryToSendMoveEvent(true); if (this.config.needsPointerData) { - this.sendTouchEvent(event); + this.sendTouchEvent(adaptedEvent); } } - protected onPointerMoveOver(_event: AdaptedEvent): void { + protected onPointerMoveOver( + _adaptedEvent: AdaptedEvent, + _originalEvent?: TouchEvent | PointerEvent + ): void { // used only by hover gesture handler atm } - protected onPointerMoveOut(_event: AdaptedEvent): void { + protected onPointerMoveOut( + _adaptedEvent: AdaptedEvent, + _originalEvent?: TouchEvent | PointerEvent + ): void { // used only by hover gesture handler atm } + private tryToSendMoveEvent(out: boolean): void { if ( this.enabled && diff --git a/src/web/handlers/PanGestureHandler.ts b/src/web/handlers/PanGestureHandler.ts index a6a180490e..7ab1f38c7d 100644 --- a/src/web/handlers/PanGestureHandler.ts +++ b/src/web/handlers/PanGestureHandler.ts @@ -246,8 +246,14 @@ export default class PanGestureHandler extends GestureHandler { } } - protected onPointerUp(event: AdaptedEvent): void { + protected onPointerUp( + event: AdaptedEvent, + ev: TouchEvent | PointerEvent + ): void { super.onPointerUp(event); + if (ev) { + ev.preventDefault(); + } if (this.currentState === State.ACTIVE) { this.lastX = this.tracker.getLastAvgX(); @@ -263,7 +269,10 @@ export default class PanGestureHandler extends GestureHandler { this.fail(); } } - protected onPointerRemove(event: AdaptedEvent): void { + protected onPointerRemove(event: AdaptedEvent, ev: TouchEvent): void { + if (ev) { + ev.preventDefault(); + } super.onPointerRemove(event); this.tracker.removeFromTracker(event.pointerId); @@ -286,9 +295,13 @@ export default class PanGestureHandler extends GestureHandler { } } - protected onPointerMove(event: AdaptedEvent): void { + protected onPointerMove(event: AdaptedEvent, ev: TouchEvent): void { this.tracker.track(event); + if (ev) { + ev.preventDefault(); + } + this.lastX = this.tracker.getLastAvgX(); this.lastY = this.tracker.getLastAvgY(); this.velocityX = this.tracker.getVelocityX(event.pointerId); @@ -299,11 +312,15 @@ export default class PanGestureHandler extends GestureHandler { super.onPointerMove(event); } - protected onPointerOutOfBounds(event: AdaptedEvent): void { + protected onPointerOutOfBounds(event: AdaptedEvent, ev: TouchEvent): void { if (this.getShouldCancelWhenOutside()) { return; } + if (ev) { + ev.preventDefault(); + } + this.tracker.track(event); this.lastX = this.tracker.getLastAvgX(); diff --git a/src/web/tools/EventManager.ts b/src/web/tools/EventManager.ts index 900c132266..a756c4819f 100644 --- a/src/web/tools/EventManager.ts +++ b/src/web/tools/EventManager.ts @@ -19,56 +19,142 @@ export default abstract class EventManager { touchEventType?: TouchEventType ): AdaptedEvent; - protected onPointerDown(_event: AdaptedEvent): void {} - protected onPointerAdd(_event: AdaptedEvent): void {} - protected onPointerUp(_event: AdaptedEvent): void {} - protected onPointerRemove(_event: AdaptedEvent): void {} - protected onPointerMove(_event: AdaptedEvent): void {} - protected onPointerLeave(_event: AdaptedEvent): void {} // called only when pointer is pressed (or touching) - protected onPointerEnter(_event: AdaptedEvent): void {} // called only when pointer is pressed (or touching) - protected onPointerCancel(_event: AdaptedEvent): void { + protected onPointerDown( + _adaptedEvent: AdaptedEvent, + _originalEven?: TouchEvent | PointerEvent + ): void {} + protected onPointerAdd( + _adaptedEvent: AdaptedEvent, + _originalEvent?: TouchEvent | PointerEvent + ): void {} + protected onPointerUp( + _adaptedEvent: AdaptedEvent, + _originalEvent?: TouchEvent | PointerEvent + ): void {} + protected onPointerRemove( + _adaptedEvent: AdaptedEvent, + _originalEvent?: TouchEvent | PointerEvent + ): void {} + protected onPointerMove( + _adaptedEvent: AdaptedEvent, + _originalEvent?: TouchEvent | PointerEvent + ): void {} + protected onPointerLeave( + _adaptedEvent: AdaptedEvent, + _originalEvent?: TouchEvent | PointerEvent + ): void {} // called only when pointer is pressed (or touching) + protected onPointerEnter( + _adaptedEvent: AdaptedEvent, + _originalEvent?: TouchEvent | PointerEvent + ): void {} // called only when pointer is pressed (or touching) + protected onPointerCancel( + _adaptedEvent: AdaptedEvent, + _originalEvent?: TouchEvent | PointerEvent + ): void { // When pointer cancel is triggered and there are more pointers on the view, only one pointer is cancelled // Because we want all pointers to be cancelled by that event, we are doing it manually by reseting handler and changing activePointersCounter to 0 // Events that correspond to removing the pointer (pointerup, touchend) have condition, that they don't perform any action when activePointersCounter // is equal to 0. This prevents counter from going to negative values, when pointers are removed from view after one of them has been cancelled } - protected onPointerOutOfBounds(_event: AdaptedEvent): void {} - protected onPointerMoveOver(_event: AdaptedEvent): void {} - protected onPointerMoveOut(_event: AdaptedEvent): void {} + protected onPointerOutOfBounds( + _adaptedEvent: AdaptedEvent, + _originalEvent?: TouchEvent | PointerEvent + ): void {} + protected onPointerMoveOver( + _adaptedEvent: AdaptedEvent, + _originalEvent?: TouchEvent | PointerEvent + ): void {} + protected onPointerMoveOut( + _adaptedEvent: AdaptedEvent, + _originalEvent?: TouchEvent | PointerEvent + ): void {} - public setOnPointerDown(callback: (event: AdaptedEvent) => void): void { + public setOnPointerDown( + callback: ( + event: AdaptedEvent, + originalEvent?: TouchEvent | PointerEvent + ) => void + ): void { this.onPointerDown = callback; } - public setOnPointerAdd(callback: (event: AdaptedEvent) => void): void { + public setOnPointerAdd( + callback: ( + event: AdaptedEvent, + originalEvent?: TouchEvent | PointerEvent + ) => void + ): void { this.onPointerAdd = callback; } - public setOnPointerUp(callback: (event: AdaptedEvent) => void): void { + public setOnPointerUp( + callback: ( + event: AdaptedEvent, + originalEvent?: TouchEvent | PointerEvent + ) => void + ): void { this.onPointerUp = callback; } - public setOnPointerRemove(callback: (event: AdaptedEvent) => void): void { + public setOnPointerRemove( + callback: ( + event: AdaptedEvent, + originalEvent?: TouchEvent | PointerEvent + ) => void + ): void { this.onPointerRemove = callback; } - public setOnPointerMove(callback: (event: AdaptedEvent) => void): void { + public setOnPointerMove( + callback: ( + event: AdaptedEvent, + originalEvent?: TouchEvent | PointerEvent + ) => void + ): void { this.onPointerMove = callback; } - public setOnPointerLeave(callback: (event: AdaptedEvent) => void): void { + public setOnPointerLeave( + callback: ( + event: AdaptedEvent, + originalEvent?: TouchEvent | PointerEvent + ) => void + ): void { this.onPointerLeave = callback; } - public setOnPointerEnter(callback: (event: AdaptedEvent) => void): void { + public setOnPointerEnter( + callback: ( + event: AdaptedEvent, + originalEvent?: TouchEvent | PointerEvent + ) => void + ): void { this.onPointerEnter = callback; } - public setOnPointerCancel(callback: (event: AdaptedEvent) => void): void { + public setOnPointerCancel( + callback: ( + event: AdaptedEvent, + originalEvent?: TouchEvent | PointerEvent + ) => void + ): void { this.onPointerCancel = callback; } public setOnPointerOutOfBounds( - callback: (event: AdaptedEvent) => void + callback: ( + event: AdaptedEvent, + originalEvent?: TouchEvent | PointerEvent + ) => void ): void { this.onPointerOutOfBounds = callback; } - public setOnPointerMoveOver(callback: (event: AdaptedEvent) => void): void { + public setOnPointerMoveOver( + callback: ( + event: AdaptedEvent, + originalEvent?: TouchEvent | PointerEvent + ) => void + ): void { this.onPointerMoveOver = callback; } - public setOnPointerMoveOut(callback: (event: AdaptedEvent) => void): void { + public setOnPointerMoveOut( + callback: ( + event: AdaptedEvent, + originalEvent?: TouchEvent | PointerEvent + ) => void + ): void { this.onPointerMoveOut = callback; } diff --git a/src/web/tools/TouchEventManager.ts b/src/web/tools/TouchEventManager.ts index aabdd0bf62..8339abe50c 100644 --- a/src/web/tools/TouchEventManager.ts +++ b/src/web/tools/TouchEventManager.ts @@ -71,7 +71,7 @@ export default class TouchEventManager extends EventManager { this.onPointerEnter(adaptedEvent); this.markAsInBounds(adaptedEvent.pointerId); } else { - this.onPointerMove(adaptedEvent); + this.onPointerMove(adaptedEvent, event); } } else { if (pointerIndex >= 0) { @@ -79,7 +79,7 @@ export default class TouchEventManager extends EventManager { this.onPointerLeave(adaptedEvent); this.markAsOutOfBounds(adaptedEvent.pointerId); } else { - this.onPointerOutOfBounds(adaptedEvent); + this.onPointerOutOfBounds(adaptedEvent, event); } } } @@ -111,9 +111,9 @@ export default class TouchEventManager extends EventManager { if (--this.activePointersCounter > 0) { adaptedEvent.eventType = EventTypes.ADDITIONAL_POINTER_UP; - this.onPointerRemove(adaptedEvent); + this.onPointerRemove(adaptedEvent, event); } else { - this.onPointerUp(adaptedEvent); + this.onPointerUp(adaptedEvent, event); } } }); From 705014fbaf15262e3cc6c97dd9ab6a11b4bfd519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bert?= Date: Mon, 16 Oct 2023 08:25:01 +0200 Subject: [PATCH 08/20] Remove ifs --- src/web/handlers/PanGestureHandler.ts | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/web/handlers/PanGestureHandler.ts b/src/web/handlers/PanGestureHandler.ts index 7ab1f38c7d..48ba86e508 100644 --- a/src/web/handlers/PanGestureHandler.ts +++ b/src/web/handlers/PanGestureHandler.ts @@ -251,9 +251,8 @@ export default class PanGestureHandler extends GestureHandler { ev: TouchEvent | PointerEvent ): void { super.onPointerUp(event); - if (ev) { - ev.preventDefault(); - } + + ev?.preventDefault(); if (this.currentState === State.ACTIVE) { this.lastX = this.tracker.getLastAvgX(); @@ -270,9 +269,8 @@ export default class PanGestureHandler extends GestureHandler { } } protected onPointerRemove(event: AdaptedEvent, ev: TouchEvent): void { - if (ev) { - ev.preventDefault(); - } + ev?.preventDefault(); + super.onPointerRemove(event); this.tracker.removeFromTracker(event.pointerId); @@ -296,11 +294,9 @@ export default class PanGestureHandler extends GestureHandler { } protected onPointerMove(event: AdaptedEvent, ev: TouchEvent): void { - this.tracker.track(event); + ev?.preventDefault(); - if (ev) { - ev.preventDefault(); - } + this.tracker.track(event); this.lastX = this.tracker.getLastAvgX(); this.lastY = this.tracker.getLastAvgY(); @@ -317,9 +313,7 @@ export default class PanGestureHandler extends GestureHandler { return; } - if (ev) { - ev.preventDefault(); - } + ev?.preventDefault(); this.tracker.track(event); From ba60cf382544be64394cc16d48d8c7dea5d15f5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bert?= Date: Mon, 16 Oct 2023 08:27:11 +0200 Subject: [PATCH 09/20] Remove confusing variable in IM --- src/web/tools/InteractionManager.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/web/tools/InteractionManager.ts b/src/web/tools/InteractionManager.ts index 0bce4a44de..b89bfa4efa 100644 --- a/src/web/tools/InteractionManager.ts +++ b/src/web/tools/InteractionManager.ts @@ -101,12 +101,11 @@ export default class InteractionManager { _handler: GestureHandler, otherHandler: GestureHandler ): boolean { - const shouldBeCancelledByScrollView = + return ( otherHandler instanceof NativeViewGestureHandler && otherHandler.getLastSentState() === State.ACTIVE && - otherHandler.getState() === State.ACTIVE; - - return shouldBeCancelledByScrollView; + otherHandler.getState() === State.ACTIVE + ); } public dropRelationsForHandlerWithTag(handlerTag: number): void { From c52da02056063ed7fec72c367cf4e0cbf74fc34d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bert?= Date: Mon, 16 Oct 2023 10:12:13 +0200 Subject: [PATCH 10/20] Prevent errors in console --- src/web/handlers/PanGestureHandler.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/web/handlers/PanGestureHandler.ts b/src/web/handlers/PanGestureHandler.ts index 48ba86e508..b69b8d141d 100644 --- a/src/web/handlers/PanGestureHandler.ts +++ b/src/web/handlers/PanGestureHandler.ts @@ -252,7 +252,9 @@ export default class PanGestureHandler extends GestureHandler { ): void { super.onPointerUp(event); - ev?.preventDefault(); + if (ev?.cancelable) { + ev.preventDefault(); + } if (this.currentState === State.ACTIVE) { this.lastX = this.tracker.getLastAvgX(); @@ -269,7 +271,9 @@ export default class PanGestureHandler extends GestureHandler { } } protected onPointerRemove(event: AdaptedEvent, ev: TouchEvent): void { - ev?.preventDefault(); + if (ev?.cancelable) { + ev.preventDefault(); + } super.onPointerRemove(event); this.tracker.removeFromTracker(event.pointerId); @@ -294,7 +298,9 @@ export default class PanGestureHandler extends GestureHandler { } protected onPointerMove(event: AdaptedEvent, ev: TouchEvent): void { - ev?.preventDefault(); + if (ev?.cancelable) { + ev.preventDefault(); + } this.tracker.track(event); @@ -313,7 +319,9 @@ export default class PanGestureHandler extends GestureHandler { return; } - ev?.preventDefault(); + if (ev?.cancelable) { + ev.preventDefault(); + } this.tracker.track(event); From 5c26a86fd4ccfd2a17e2d54e49d54a50c5b2843a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bert?= Date: Tue, 17 Oct 2023 10:42:28 +0200 Subject: [PATCH 11/20] Match android naming convention --- src/web/handlers/GestureHandler.ts | 64 +++++++++++++------------- src/web/handlers/PanGestureHandler.ts | 30 +++++++----- src/web/tools/EventManager.ts | 66 +++++++++++++-------------- 3 files changed, 83 insertions(+), 77 deletions(-) diff --git a/src/web/handlers/GestureHandler.ts b/src/web/handlers/GestureHandler.ts index d77cd5b2bd..6a2020d983 100644 --- a/src/web/handlers/GestureHandler.ts +++ b/src/web/handlers/GestureHandler.ts @@ -273,58 +273,58 @@ export default abstract class GestureHandler { // protected onPointerDown( - adaptedEvent: AdaptedEvent, - _originalEvent?: TouchEvent | PointerEvent + event: AdaptedEvent, + _sourceEvent?: TouchEvent | PointerEvent ): void { GestureHandlerOrchestrator.getInstance().recordHandlerIfNotPresent(this); - this.pointerType = adaptedEvent.pointerType; + this.pointerType = event.pointerType; if (this.pointerType === PointerType.TOUCH) { GestureHandlerOrchestrator.getInstance().cancelMouseAndPenGestures(this); } if (this.config.needsPointerData) { - this.sendTouchEvent(adaptedEvent); + this.sendTouchEvent(event); } } // Adding another pointer to existing ones protected onPointerAdd( - adaptedEvent: AdaptedEvent, - _originalEvent?: TouchEvent | PointerEvent + event: AdaptedEvent, + _sourceEvent?: TouchEvent | PointerEvent ): void { if (this.config.needsPointerData) { - this.sendTouchEvent(adaptedEvent); + this.sendTouchEvent(event); } } protected onPointerUp( - adaptedEvent: AdaptedEvent, - _originalEvent?: TouchEvent | PointerEvent + event: AdaptedEvent, + _sourceEvent?: TouchEvent | PointerEvent ): void { if (this.config.needsPointerData) { - this.sendTouchEvent(adaptedEvent); + this.sendTouchEvent(event); } } // Removing pointer, when there is more than one pointers protected onPointerRemove( - adaptedEvent: AdaptedEvent, - _originalEvent?: TouchEvent | PointerEvent + event: AdaptedEvent, + _sourceEvent?: TouchEvent | PointerEvent ): void { if (this.config.needsPointerData) { - this.sendTouchEvent(adaptedEvent); + this.sendTouchEvent(event); } } protected onPointerMove( - adaptedEvent: AdaptedEvent, - _originalEvent?: TouchEvent | PointerEvent + event: AdaptedEvent, + _sourceEvent?: TouchEvent | PointerEvent ): void { this.tryToSendMoveEvent(false); if (this.config.needsPointerData) { - this.sendTouchEvent(adaptedEvent); + this.sendTouchEvent(event); } } protected onPointerLeave( - adaptedEvent: AdaptedEvent, - _originalEvent?: TouchEvent | PointerEvent + event: AdaptedEvent, + _sourceEvent?: TouchEvent | PointerEvent ): void { if (this.shouldCancellWhenOutside) { switch (this.currentState) { @@ -339,46 +339,46 @@ export default abstract class GestureHandler { } if (this.config.needsPointerData) { - this.sendTouchEvent(adaptedEvent); + this.sendTouchEvent(event); } } protected onPointerEnter( - adaptedEvent: AdaptedEvent, - _originalEvent?: TouchEvent | PointerEvent + event: AdaptedEvent, + _sourceEvent?: TouchEvent | PointerEvent ): void { if (this.config.needsPointerData) { - this.sendTouchEvent(adaptedEvent); + this.sendTouchEvent(event); } } protected onPointerCancel( - adaptedEvent: AdaptedEvent, - _originalEvent?: TouchEvent | PointerEvent + event: AdaptedEvent, + _sourceEvent?: TouchEvent | PointerEvent ): void { if (this.config.needsPointerData) { - this.sendTouchEvent(adaptedEvent); + this.sendTouchEvent(event); } this.cancel(); this.reset(); } protected onPointerOutOfBounds( - adaptedEvent: AdaptedEvent, - _originalEvent?: TouchEvent | PointerEvent + event: AdaptedEvent, + _sourceEvent?: TouchEvent | PointerEvent ): void { this.tryToSendMoveEvent(true); if (this.config.needsPointerData) { - this.sendTouchEvent(adaptedEvent); + this.sendTouchEvent(event); } } protected onPointerMoveOver( - _adaptedEvent: AdaptedEvent, - _originalEvent?: TouchEvent | PointerEvent + _event: AdaptedEvent, + _sourceEvent?: TouchEvent | PointerEvent ): void { // used only by hover gesture handler atm } protected onPointerMoveOut( - _adaptedEvent: AdaptedEvent, - _originalEvent?: TouchEvent | PointerEvent + _event: AdaptedEvent, + _sourceEvent?: TouchEvent | PointerEvent ): void { // used only by hover gesture handler atm } diff --git a/src/web/handlers/PanGestureHandler.ts b/src/web/handlers/PanGestureHandler.ts index b69b8d141d..2a2c51a2c9 100644 --- a/src/web/handlers/PanGestureHandler.ts +++ b/src/web/handlers/PanGestureHandler.ts @@ -248,12 +248,12 @@ export default class PanGestureHandler extends GestureHandler { protected onPointerUp( event: AdaptedEvent, - ev: TouchEvent | PointerEvent + sourceEvent?: TouchEvent | PointerEvent ): void { super.onPointerUp(event); - if (ev?.cancelable) { - ev.preventDefault(); + if (sourceEvent?.cancelable) { + sourceEvent.preventDefault(); } if (this.currentState === State.ACTIVE) { @@ -270,9 +270,12 @@ export default class PanGestureHandler extends GestureHandler { this.fail(); } } - protected onPointerRemove(event: AdaptedEvent, ev: TouchEvent): void { - if (ev?.cancelable) { - ev.preventDefault(); + protected onPointerRemove( + event: AdaptedEvent, + sourceEvent?: TouchEvent + ): void { + if (sourceEvent?.cancelable) { + sourceEvent.preventDefault(); } super.onPointerRemove(event); @@ -297,9 +300,9 @@ export default class PanGestureHandler extends GestureHandler { } } - protected onPointerMove(event: AdaptedEvent, ev: TouchEvent): void { - if (ev?.cancelable) { - ev.preventDefault(); + protected onPointerMove(event: AdaptedEvent, sourceEvent?: TouchEvent): void { + if (sourceEvent?.cancelable) { + sourceEvent.preventDefault(); } this.tracker.track(event); @@ -314,13 +317,16 @@ export default class PanGestureHandler extends GestureHandler { super.onPointerMove(event); } - protected onPointerOutOfBounds(event: AdaptedEvent, ev: TouchEvent): void { + protected onPointerOutOfBounds( + event: AdaptedEvent, + sourceEvent?: TouchEvent + ): void { if (this.getShouldCancelWhenOutside()) { return; } - if (ev?.cancelable) { - ev.preventDefault(); + if (sourceEvent?.cancelable) { + sourceEvent.preventDefault(); } this.tracker.track(event); diff --git a/src/web/tools/EventManager.ts b/src/web/tools/EventManager.ts index a756c4819f..e1f9cc7582 100644 --- a/src/web/tools/EventManager.ts +++ b/src/web/tools/EventManager.ts @@ -20,36 +20,36 @@ export default abstract class EventManager { ): AdaptedEvent; protected onPointerDown( - _adaptedEvent: AdaptedEvent, - _originalEven?: TouchEvent | PointerEvent + _event: AdaptedEvent, + _sourceEvent?: TouchEvent | PointerEvent ): void {} protected onPointerAdd( - _adaptedEvent: AdaptedEvent, - _originalEvent?: TouchEvent | PointerEvent + _event: AdaptedEvent, + _sourceEvent?: TouchEvent | PointerEvent ): void {} protected onPointerUp( - _adaptedEvent: AdaptedEvent, - _originalEvent?: TouchEvent | PointerEvent + _event: AdaptedEvent, + _sourceEvent?: TouchEvent | PointerEvent ): void {} protected onPointerRemove( - _adaptedEvent: AdaptedEvent, - _originalEvent?: TouchEvent | PointerEvent + _event: AdaptedEvent, + _sourceEvent?: TouchEvent | PointerEvent ): void {} protected onPointerMove( - _adaptedEvent: AdaptedEvent, - _originalEvent?: TouchEvent | PointerEvent + _event: AdaptedEvent, + _sourceEvent?: TouchEvent | PointerEvent ): void {} protected onPointerLeave( - _adaptedEvent: AdaptedEvent, - _originalEvent?: TouchEvent | PointerEvent + _event: AdaptedEvent, + _sourceEvent?: TouchEvent | PointerEvent ): void {} // called only when pointer is pressed (or touching) protected onPointerEnter( - _adaptedEvent: AdaptedEvent, - _originalEvent?: TouchEvent | PointerEvent + _event: AdaptedEvent, + _sourceEvent?: TouchEvent | PointerEvent ): void {} // called only when pointer is pressed (or touching) protected onPointerCancel( - _adaptedEvent: AdaptedEvent, - _originalEvent?: TouchEvent | PointerEvent + _event: AdaptedEvent, + _sourceEvent?: TouchEvent | PointerEvent ): void { // When pointer cancel is triggered and there are more pointers on the view, only one pointer is cancelled // Because we want all pointers to be cancelled by that event, we are doing it manually by reseting handler and changing activePointersCounter to 0 @@ -57,22 +57,22 @@ export default abstract class EventManager { // is equal to 0. This prevents counter from going to negative values, when pointers are removed from view after one of them has been cancelled } protected onPointerOutOfBounds( - _adaptedEvent: AdaptedEvent, - _originalEvent?: TouchEvent | PointerEvent + _event: AdaptedEvent, + _sourceEvent?: TouchEvent | PointerEvent ): void {} protected onPointerMoveOver( - _adaptedEvent: AdaptedEvent, - _originalEvent?: TouchEvent | PointerEvent + _event: AdaptedEvent, + _sourceEvent?: TouchEvent | PointerEvent ): void {} protected onPointerMoveOut( - _adaptedEvent: AdaptedEvent, - _originalEvent?: TouchEvent | PointerEvent + _event: AdaptedEvent, + _sourceEvent?: TouchEvent | PointerEvent ): void {} public setOnPointerDown( callback: ( event: AdaptedEvent, - originalEvent?: TouchEvent | PointerEvent + sourceEvent?: TouchEvent | PointerEvent ) => void ): void { this.onPointerDown = callback; @@ -80,7 +80,7 @@ export default abstract class EventManager { public setOnPointerAdd( callback: ( event: AdaptedEvent, - originalEvent?: TouchEvent | PointerEvent + sourceEvent?: TouchEvent | PointerEvent ) => void ): void { this.onPointerAdd = callback; @@ -88,7 +88,7 @@ export default abstract class EventManager { public setOnPointerUp( callback: ( event: AdaptedEvent, - originalEvent?: TouchEvent | PointerEvent + sourceEvent?: TouchEvent | PointerEvent ) => void ): void { this.onPointerUp = callback; @@ -96,7 +96,7 @@ export default abstract class EventManager { public setOnPointerRemove( callback: ( event: AdaptedEvent, - originalEvent?: TouchEvent | PointerEvent + sourceEvent?: TouchEvent | PointerEvent ) => void ): void { this.onPointerRemove = callback; @@ -104,7 +104,7 @@ export default abstract class EventManager { public setOnPointerMove( callback: ( event: AdaptedEvent, - originalEvent?: TouchEvent | PointerEvent + sourceEvent?: TouchEvent | PointerEvent ) => void ): void { this.onPointerMove = callback; @@ -112,7 +112,7 @@ export default abstract class EventManager { public setOnPointerLeave( callback: ( event: AdaptedEvent, - originalEvent?: TouchEvent | PointerEvent + sourceEvent?: TouchEvent | PointerEvent ) => void ): void { this.onPointerLeave = callback; @@ -120,7 +120,7 @@ export default abstract class EventManager { public setOnPointerEnter( callback: ( event: AdaptedEvent, - originalEvent?: TouchEvent | PointerEvent + sourceEvent?: TouchEvent | PointerEvent ) => void ): void { this.onPointerEnter = callback; @@ -128,7 +128,7 @@ export default abstract class EventManager { public setOnPointerCancel( callback: ( event: AdaptedEvent, - originalEvent?: TouchEvent | PointerEvent + sourceEvent?: TouchEvent | PointerEvent ) => void ): void { this.onPointerCancel = callback; @@ -136,7 +136,7 @@ export default abstract class EventManager { public setOnPointerOutOfBounds( callback: ( event: AdaptedEvent, - originalEvent?: TouchEvent | PointerEvent + sourceEvent?: TouchEvent | PointerEvent ) => void ): void { this.onPointerOutOfBounds = callback; @@ -144,7 +144,7 @@ export default abstract class EventManager { public setOnPointerMoveOver( callback: ( event: AdaptedEvent, - originalEvent?: TouchEvent | PointerEvent + sourceEvent?: TouchEvent | PointerEvent ) => void ): void { this.onPointerMoveOver = callback; @@ -152,7 +152,7 @@ export default abstract class EventManager { public setOnPointerMoveOut( callback: ( event: AdaptedEvent, - originalEvent?: TouchEvent | PointerEvent + sourceEvent?: TouchEvent | PointerEvent ) => void ): void { this.onPointerMoveOut = callback; From cf5e1cc89a8febd6e07649c7e3af630d238e1c86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bert?= Date: Tue, 17 Oct 2023 10:45:35 +0200 Subject: [PATCH 12/20] Add missing PointerEvent types --- src/web/handlers/PanGestureHandler.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/web/handlers/PanGestureHandler.ts b/src/web/handlers/PanGestureHandler.ts index 2a2c51a2c9..029a404137 100644 --- a/src/web/handlers/PanGestureHandler.ts +++ b/src/web/handlers/PanGestureHandler.ts @@ -272,7 +272,7 @@ export default class PanGestureHandler extends GestureHandler { } protected onPointerRemove( event: AdaptedEvent, - sourceEvent?: TouchEvent + sourceEvent?: TouchEvent | PointerEvent ): void { if (sourceEvent?.cancelable) { sourceEvent.preventDefault(); @@ -300,7 +300,10 @@ export default class PanGestureHandler extends GestureHandler { } } - protected onPointerMove(event: AdaptedEvent, sourceEvent?: TouchEvent): void { + protected onPointerMove( + event: AdaptedEvent, + sourceEvent?: TouchEvent | PointerEvent + ): void { if (sourceEvent?.cancelable) { sourceEvent.preventDefault(); } @@ -319,7 +322,7 @@ export default class PanGestureHandler extends GestureHandler { protected onPointerOutOfBounds( event: AdaptedEvent, - sourceEvent?: TouchEvent + sourceEvent?: TouchEvent | PointerEvent ): void { if (this.getShouldCancelWhenOutside()) { return; From 965487361dd27c6e194f00cbaacf6bbae1e47c60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bert?= Date: Thu, 19 Oct 2023 14:50:00 +0200 Subject: [PATCH 13/20] Remove getLastSentState --- src/web/handlers/GestureHandler.ts | 4 ---- src/web/tools/InteractionManager.ts | 1 - 2 files changed, 5 deletions(-) diff --git a/src/web/handlers/GestureHandler.ts b/src/web/handlers/GestureHandler.ts index 6a2020d983..00e5755c3b 100644 --- a/src/web/handlers/GestureHandler.ts +++ b/src/web/handlers/GestureHandler.ts @@ -804,10 +804,6 @@ export default abstract class GestureHandler { return this.currentState; } - public getLastSentState(): State | null { - return this.lastSentState; - } - public isEnabled(): boolean { return this.enabled; } diff --git a/src/web/tools/InteractionManager.ts b/src/web/tools/InteractionManager.ts index b89bfa4efa..1732f8e06f 100644 --- a/src/web/tools/InteractionManager.ts +++ b/src/web/tools/InteractionManager.ts @@ -103,7 +103,6 @@ export default class InteractionManager { ): boolean { return ( otherHandler instanceof NativeViewGestureHandler && - otherHandler.getLastSentState() === State.ACTIVE && otherHandler.getState() === State.ACTIVE ); } From a7a61828d5b8cdc225377f9c90fd42d5c8e9b616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bert?= Date: Thu, 16 Nov 2023 15:29:51 +0100 Subject: [PATCH 14/20] Minor changes --- src/web/handlers/PanGestureHandler.ts | 14 +++++++++++++- src/web/tools/InteractionManager.ts | 10 ++-------- src/web/tools/TouchEventManager.ts | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/web/handlers/PanGestureHandler.ts b/src/web/handlers/PanGestureHandler.ts index 029a404137..d2e7fb051c 100644 --- a/src/web/handlers/PanGestureHandler.ts +++ b/src/web/handlers/PanGestureHandler.ts @@ -54,6 +54,8 @@ export default class PanGestureHandler extends GestureHandler { private activateAfterLongPress = 0; private activationTimeout = 0; + private shouldBlockEvents = true; + public init(ref: number, propsRef: React.RefObject): void { super.init(ref, propsRef); } @@ -304,8 +306,10 @@ export default class PanGestureHandler extends GestureHandler { event: AdaptedEvent, sourceEvent?: TouchEvent | PointerEvent ): void { - if (sourceEvent?.cancelable) { + if (sourceEvent?.cancelable && this.shouldBlockEvents) { sourceEvent.preventDefault(); + } else if (sourceEvent) { + this.fail(); } this.tracker.track(event); @@ -494,8 +498,16 @@ export default class PanGestureHandler extends GestureHandler { super.activate(force); } + public fail(_sendIfDisabled?: boolean): void { + this.shouldBlockEvents = false; + super.fail(); + this.shouldBlockEvents = true; + } + protected onCancel(): void { + this.shouldBlockEvents = false; this.clearActivationTimeout(); + this.shouldBlockEvents = true; } protected onReset(): void { diff --git a/src/web/tools/InteractionManager.ts b/src/web/tools/InteractionManager.ts index 1732f8e06f..2f62db1f27 100644 --- a/src/web/tools/InteractionManager.ts +++ b/src/web/tools/InteractionManager.ts @@ -1,7 +1,5 @@ -import NativeViewGestureHandler from '../handlers/NativeViewGestureHandler'; import GestureHandler from '../handlers/GestureHandler'; import { Config, Handler } from '../interfaces'; -import { State } from '../../State'; export default class InteractionManager { private static instance: InteractionManager; @@ -99,12 +97,9 @@ export default class InteractionManager { public shouldHandlerBeCancelledBy( _handler: GestureHandler, - otherHandler: GestureHandler + _otherHandler: GestureHandler ): boolean { - return ( - otherHandler instanceof NativeViewGestureHandler && - otherHandler.getState() === State.ACTIVE - ); + return false; } public dropRelationsForHandlerWithTag(handlerTag: number): void { @@ -114,7 +109,6 @@ export default class InteractionManager { public reset() { this.waitForRelations.clear(); - this.simultaneousRelations.clear(); } public static getInstance(): InteractionManager { diff --git a/src/web/tools/TouchEventManager.ts b/src/web/tools/TouchEventManager.ts index 8339abe50c..7ebd71121a 100644 --- a/src/web/tools/TouchEventManager.ts +++ b/src/web/tools/TouchEventManager.ts @@ -38,7 +38,7 @@ export default class TouchEventManager extends EventManager { adaptedEvent.eventType = EventTypes.ADDITIONAL_POINTER_DOWN; this.onPointerAdd(adaptedEvent); } else { - this.onPointerDown(adaptedEvent); + this.onPointerDown(adaptedEvent, event); } } }); From be7809c6777cf03e58501284d98c4dcfca759287 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bert?= Date: Mon, 20 Nov 2023 08:25:07 +0100 Subject: [PATCH 15/20] bring back simultaneousRelations clear --- src/web/tools/InteractionManager.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/web/tools/InteractionManager.ts b/src/web/tools/InteractionManager.ts index 2f62db1f27..3419482321 100644 --- a/src/web/tools/InteractionManager.ts +++ b/src/web/tools/InteractionManager.ts @@ -109,6 +109,7 @@ export default class InteractionManager { public reset() { this.waitForRelations.clear(); + this.simultaneousRelations.clear(); } public static getInstance(): InteractionManager { From 7fdfc57928b05667361f874b5f72f88456319782 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bert?= Date: Mon, 20 Nov 2023 08:35:13 +0100 Subject: [PATCH 16/20] Remove shouldBlockEvents flag --- src/web/handlers/PanGestureHandler.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/web/handlers/PanGestureHandler.ts b/src/web/handlers/PanGestureHandler.ts index d2e7fb051c..58e701679f 100644 --- a/src/web/handlers/PanGestureHandler.ts +++ b/src/web/handlers/PanGestureHandler.ts @@ -54,8 +54,6 @@ export default class PanGestureHandler extends GestureHandler { private activateAfterLongPress = 0; private activationTimeout = 0; - private shouldBlockEvents = true; - public init(ref: number, propsRef: React.RefObject): void { super.init(ref, propsRef); } @@ -306,7 +304,7 @@ export default class PanGestureHandler extends GestureHandler { event: AdaptedEvent, sourceEvent?: TouchEvent | PointerEvent ): void { - if (sourceEvent?.cancelable && this.shouldBlockEvents) { + if (sourceEvent?.cancelable) { sourceEvent.preventDefault(); } else if (sourceEvent) { this.fail(); @@ -499,15 +497,11 @@ export default class PanGestureHandler extends GestureHandler { } public fail(_sendIfDisabled?: boolean): void { - this.shouldBlockEvents = false; super.fail(); - this.shouldBlockEvents = true; } protected onCancel(): void { - this.shouldBlockEvents = false; this.clearActivationTimeout(); - this.shouldBlockEvents = true; } protected onReset(): void { From 74436a21441bd5208f52a7bc98e48ce9c5a02807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bert?= Date: Mon, 20 Nov 2023 10:54:10 +0100 Subject: [PATCH 17/20] Add event cancelation to other handlers --- src/web/handlers/FlingGestureHandler.ts | 11 +++++++++- src/web/handlers/ManualGestureHandler.ts | 22 ++++++++++++++++++-- src/web/handlers/PinchGestureHandler.ts | 24 ++++++++++++++++++++-- src/web/handlers/RotationGestureHandler.ts | 22 ++++++++++++++++++-- 4 files changed, 72 insertions(+), 7 deletions(-) diff --git a/src/web/handlers/FlingGestureHandler.ts b/src/web/handlers/FlingGestureHandler.ts index 0c2a117b2d..fda007e903 100644 --- a/src/web/handlers/FlingGestureHandler.ts +++ b/src/web/handlers/FlingGestureHandler.ts @@ -116,13 +116,22 @@ export default class FlingGestureHandler extends GestureHandler { } } - protected onPointerMove(event: AdaptedEvent): void { + protected onPointerMove( + event: AdaptedEvent, + sourceEvent: PointerEvent | TouchEvent + ): void { this.tracker.track(event); if (this.currentState !== State.BEGAN) { return; } + if (sourceEvent?.cancelable) { + sourceEvent.preventDefault(); + } else if (sourceEvent) { + this.fail(); + } + this.tryEndFling(); super.onPointerMove(event); diff --git a/src/web/handlers/ManualGestureHandler.ts b/src/web/handlers/ManualGestureHandler.ts index c04e21669b..701af8590b 100644 --- a/src/web/handlers/ManualGestureHandler.ts +++ b/src/web/handlers/ManualGestureHandler.ts @@ -21,12 +21,30 @@ export default class ManualGestureHandler extends GestureHandler { super.onPointerAdd(event); } - protected onPointerMove(event: AdaptedEvent): void { + protected onPointerMove( + event: AdaptedEvent, + sourceEvent: PointerEvent | TouchEvent + ): void { + if (sourceEvent?.cancelable) { + sourceEvent.preventDefault(); + } else if (sourceEvent) { + this.fail(); + } + this.tracker.track(event); super.onPointerMove(event); } - protected onPointerOutOfBounds(event: AdaptedEvent): void { + protected onPointerOutOfBounds( + event: AdaptedEvent, + sourceEvent: PointerEvent | TouchEvent + ): void { + if (sourceEvent?.cancelable) { + sourceEvent.preventDefault(); + } else if (sourceEvent) { + this.fail(); + } + this.tracker.track(event); super.onPointerOutOfBounds(event); } diff --git a/src/web/handlers/PinchGestureHandler.ts b/src/web/handlers/PinchGestureHandler.ts index 646cff0ff0..5afc7a4345 100644 --- a/src/web/handlers/PinchGestureHandler.ts +++ b/src/web/handlers/PinchGestureHandler.ts @@ -108,19 +108,39 @@ export default class PinchGestureHandler extends GestureHandler { } } - protected onPointerMove(event: AdaptedEvent): void { + protected onPointerMove( + event: AdaptedEvent, + sourceEvent: PointerEvent | TouchEvent + ): void { if (this.tracker.getTrackedPointersCount() < 2) { return; } + + if (sourceEvent?.cancelable) { + sourceEvent.preventDefault(); + } else if (sourceEvent) { + this.fail(); + } + this.tracker.track(event); this.scaleGestureDetector.onTouchEvent(event, this.tracker); super.onPointerMove(event); } - protected onPointerOutOfBounds(event: AdaptedEvent): void { + protected onPointerOutOfBounds( + event: AdaptedEvent, + sourceEvent: PointerEvent | TouchEvent + ): void { if (this.tracker.getTrackedPointersCount() < 2) { return; } + + if (sourceEvent?.cancelable) { + sourceEvent.preventDefault(); + } else if (sourceEvent) { + this.fail(); + } + this.tracker.track(event); this.scaleGestureDetector.onTouchEvent(event, this.tracker); diff --git a/src/web/handlers/RotationGestureHandler.ts b/src/web/handlers/RotationGestureHandler.ts index 38e40e854d..3871b34fca 100644 --- a/src/web/handlers/RotationGestureHandler.ts +++ b/src/web/handlers/RotationGestureHandler.ts @@ -88,11 +88,20 @@ export default class RotationGestureHandler extends GestureHandler { this.rotationGestureDetector.onTouchEvent(event, this.tracker); } - protected onPointerMove(event: AdaptedEvent): void { + protected onPointerMove( + event: AdaptedEvent, + sourceEvent: PointerEvent | TouchEvent + ): void { if (this.tracker.getTrackedPointersCount() < 2) { return; } + if (sourceEvent?.cancelable) { + sourceEvent.preventDefault(); + } else if (sourceEvent) { + this.fail(); + } + if (this.getAnchorX()) { this.cachedAnchorX = this.getAnchorX(); } @@ -107,11 +116,20 @@ export default class RotationGestureHandler extends GestureHandler { super.onPointerMove(event); } - protected onPointerOutOfBounds(event: AdaptedEvent): void { + protected onPointerOutOfBounds( + event: AdaptedEvent, + sourceEvent: PointerEvent | TouchEvent + ): void { if (this.tracker.getTrackedPointersCount() < 2) { return; } + if (sourceEvent?.cancelable) { + sourceEvent.preventDefault(); + } else if (sourceEvent) { + this.fail(); + } + if (this.getAnchorX()) { this.cachedAnchorX = this.getAnchorX(); } From 6bb207ae4811faa9ff9f039e51c4fb476828e669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bert?= Date: Mon, 20 Nov 2023 11:57:02 +0100 Subject: [PATCH 18/20] Change logic in pan --- src/web/handlers/PanGestureHandler.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/web/handlers/PanGestureHandler.ts b/src/web/handlers/PanGestureHandler.ts index 58e701679f..1dad62c7c0 100644 --- a/src/web/handlers/PanGestureHandler.ts +++ b/src/web/handlers/PanGestureHandler.ts @@ -304,10 +304,15 @@ export default class PanGestureHandler extends GestureHandler { event: AdaptedEvent, sourceEvent?: TouchEvent | PointerEvent ): void { - if (sourceEvent?.cancelable) { - sourceEvent.preventDefault(); - } else if (sourceEvent) { - this.fail(); + if (sourceEvent) { + const state = this.getState(); + if (sourceEvent.cancelable && state === State.ACTIVE) { + sourceEvent.preventDefault(); + } + + if (!sourceEvent.cancelable && state === State.ACTIVE) { + this.fail(); + } } this.tracker.track(event); From d8545201652f3aa630e01e7b8522e2da687e211a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bert?= Date: Mon, 20 Nov 2023 12:39:31 +0100 Subject: [PATCH 19/20] Add return --- src/web/handlers/PanGestureHandler.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/web/handlers/PanGestureHandler.ts b/src/web/handlers/PanGestureHandler.ts index 1dad62c7c0..4ccc75f0cb 100644 --- a/src/web/handlers/PanGestureHandler.ts +++ b/src/web/handlers/PanGestureHandler.ts @@ -312,6 +312,7 @@ export default class PanGestureHandler extends GestureHandler { if (!sourceEvent.cancelable && state === State.ACTIVE) { this.fail(); + return; } } From d458ad6bdff3dca995908114bfcd9debe7660c58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bert?= Date: Fri, 24 Nov 2023 08:46:04 +0100 Subject: [PATCH 20/20] Change onPointerOutOfBounds --- src/web/handlers/PanGestureHandler.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/web/handlers/PanGestureHandler.ts b/src/web/handlers/PanGestureHandler.ts index 4ccc75f0cb..0b0b4879aa 100644 --- a/src/web/handlers/PanGestureHandler.ts +++ b/src/web/handlers/PanGestureHandler.ts @@ -336,8 +336,16 @@ export default class PanGestureHandler extends GestureHandler { return; } - if (sourceEvent?.cancelable) { - sourceEvent.preventDefault(); + if (sourceEvent) { + const state = this.getState(); + if (sourceEvent.cancelable && state === State.ACTIVE) { + sourceEvent.preventDefault(); + } + + if (!sourceEvent.cancelable && state === State.ACTIVE) { + this.fail(); + return; + } } this.tracker.track(event);