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

Fix scroll interactions #2631

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
000749a
Get info about ScrollView
m-bert Oct 6, 2023
e4b09cb
Simplify if
m-bert Oct 11, 2023
756505d
Remove touchAction
m-bert Oct 12, 2023
3298f86
Implement shouldHandlerBeCancelledBy
m-bert Oct 12, 2023
2f77ae4
add getLastSentState
m-bert Oct 12, 2023
c5a953f
remove isScrollView
m-bert Oct 12, 2023
922622d
add preventDefault to Pan
m-bert Oct 12, 2023
705014f
Remove ifs
m-bert Oct 16, 2023
ba60cf3
Remove confusing variable in IM
m-bert Oct 16, 2023
62d77ed
Merge branch 'main' into @mbert/fix-scroll-interactions
m-bert Oct 16, 2023
c52da02
Prevent errors in console
m-bert Oct 16, 2023
5c26a86
Match android naming convention
m-bert Oct 17, 2023
cf5e1cc
Add missing PointerEvent types
m-bert Oct 17, 2023
7aba2e0
Merge branch 'main' into @mbert/fix-scroll-interactions
m-bert Oct 17, 2023
496744b
Merge branch 'main' into @mbert/fix-scroll-interactions
m-bert Oct 17, 2023
0102036
Merge branch 'main' into @mbert/fix-scroll-interactions
m-bert Oct 18, 2023
9654873
Remove getLastSentState
m-bert Oct 19, 2023
72f39c1
Merge branch 'main' into @mbert/fix-scroll-interactions
m-bert Oct 19, 2023
49a015b
Merge branch 'main' into @mbert/fix-scroll-interactions
m-bert Oct 25, 2023
048598a
Merge branch 'main' into @mbert/fix-scroll-interactions
m-bert Oct 30, 2023
43165fa
Merge branch 'main' into @mbert/fix-scroll-interactions
m-bert Oct 31, 2023
0ea45f3
Merge branch 'main' into @mbert/fix-scroll-interactions
m-bert Nov 6, 2023
bb5229a
Merge branch 'main' into @mbert/fix-scroll-interactions
m-bert Nov 7, 2023
a7a6182
Minor changes
m-bert Nov 16, 2023
987b3a7
Merge branch 'main' into @mbert/fix-scroll-interactions
m-bert Nov 20, 2023
be7809c
bring back simultaneousRelations clear
m-bert Nov 20, 2023
7fdfc57
Remove shouldBlockEvents flag
m-bert Nov 20, 2023
74436a2
Add event cancelation to other handlers
m-bert Nov 20, 2023
6bb207a
Change logic in pan
m-bert Nov 20, 2023
d854520
Add return
m-bert Nov 20, 2023
7a731c4
Merge branch 'main' into @mbert/fix-scroll-interactions
m-bert Nov 21, 2023
d544643
Merge branch 'main' into @mbert/fix-scroll-interactions
m-bert Nov 21, 2023
d458ad6
Change onPointerOutOfBounds
m-bert Nov 24, 2023
d337505
Merge branch 'main' into @mbert/fix-scroll-interactions
m-bert Nov 24, 2023
77c4d36
Merge branch 'main' into @mbert/fix-scroll-interactions
m-bert Dec 14, 2023
dd2a3d3
Merge branch 'main' into @mbert/fix-scroll-interactions
m-bert Jan 2, 2024
921efa1
Merge branch 'main' into @mbert/fix-scroll-interactions
m-bert Feb 20, 2024
f76457b
Merge branch 'main' into @mbert/fix-scroll-interactions
m-bert Feb 21, 2024
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
11 changes: 10 additions & 1 deletion src/web/handlers/FlingGestureHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,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);
Expand Down
56 changes: 45 additions & 11 deletions src/web/handlers/GestureHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,10 @@ export default abstract class GestureHandler {
// Event actions
//

protected onPointerDown(event: AdaptedEvent): void {
protected onPointerDown(
event: AdaptedEvent,
_sourceEvent?: TouchEvent | PointerEvent
): void {
GestureHandlerOrchestrator.getInstance().recordHandlerIfNotPresent(this);
this.pointerType = event.pointerType;

Expand All @@ -290,29 +293,44 @@ export default abstract class GestureHandler {
}
}
// Adding another pointer to existing ones
protected onPointerAdd(event: AdaptedEvent): void {
protected onPointerAdd(
event: AdaptedEvent,
_sourceEvent?: TouchEvent | PointerEvent
): void {
if (this.config.needsPointerData) {
this.sendTouchEvent(event);
}
}
protected onPointerUp(event: AdaptedEvent): void {
protected onPointerUp(
event: AdaptedEvent,
_sourceEvent?: TouchEvent | PointerEvent
): void {
if (this.config.needsPointerData) {
this.sendTouchEvent(event);
}
}
// Removing pointer, when there is more than one pointers
protected onPointerRemove(event: AdaptedEvent): void {
protected onPointerRemove(
event: AdaptedEvent,
_sourceEvent?: TouchEvent | PointerEvent
): void {
if (this.config.needsPointerData) {
this.sendTouchEvent(event);
}
}
protected onPointerMove(event: AdaptedEvent): void {
protected onPointerMove(
event: AdaptedEvent,
_sourceEvent?: TouchEvent | PointerEvent
): void {
this.tryToSendMoveEvent(false);
if (this.config.needsPointerData) {
this.sendTouchEvent(event);
}
}
protected onPointerLeave(event: AdaptedEvent): void {
protected onPointerLeave(
event: AdaptedEvent,
_sourceEvent?: TouchEvent | PointerEvent
): void {
if (this.shouldCancellWhenOutside) {
switch (this.currentState) {
case State.ACTIVE:
Expand All @@ -329,31 +347,47 @@ export default abstract class GestureHandler {
this.sendTouchEvent(event);
}
}
protected onPointerEnter(event: AdaptedEvent): void {
protected onPointerEnter(
event: AdaptedEvent,
_sourceEvent?: TouchEvent | PointerEvent
): void {
if (this.config.needsPointerData) {
this.sendTouchEvent(event);
}
}
protected onPointerCancel(event: AdaptedEvent): void {
protected onPointerCancel(
event: AdaptedEvent,
_sourceEvent?: TouchEvent | PointerEvent
): void {
if (this.config.needsPointerData) {
this.sendTouchEvent(event);
}

this.cancel();
this.reset();
}
protected onPointerOutOfBounds(event: AdaptedEvent): void {
protected onPointerOutOfBounds(
event: AdaptedEvent,
_sourceEvent?: TouchEvent | PointerEvent
): void {
this.tryToSendMoveEvent(true);
if (this.config.needsPointerData) {
this.sendTouchEvent(event);
}
}
protected onPointerMoveOver(_event: AdaptedEvent): void {
protected onPointerMoveOver(
_event: AdaptedEvent,
_sourceEvent?: TouchEvent | PointerEvent
): void {
// used only by hover gesture handler atm
}
protected onPointerMoveOut(_event: AdaptedEvent): void {
protected onPointerMoveOut(
_event: AdaptedEvent,
_sourceEvent?: TouchEvent | PointerEvent
): void {
// used only by hover gesture handler atm
}

private tryToSendMoveEvent(out: boolean): void {
if (
this.enabled &&
Expand Down
22 changes: 20 additions & 2 deletions src/web/handlers/ManualGestureHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
56 changes: 52 additions & 4 deletions src/web/handlers/PanGestureHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,16 @@ export default class PanGestureHandler extends GestureHandler {
}
}

protected onPointerUp(event: AdaptedEvent): void {
protected onPointerUp(
event: AdaptedEvent,
sourceEvent?: TouchEvent | PointerEvent
): void {
super.onPointerUp(event);

if (sourceEvent?.cancelable) {
m-bert marked this conversation as resolved.
Show resolved Hide resolved
sourceEvent.preventDefault();
}

if (this.currentState === State.ACTIVE) {
this.lastX = this.tracker.getLastAvgX();
this.lastY = this.tracker.getLastAvgY();
Expand All @@ -267,7 +274,14 @@ export default class PanGestureHandler extends GestureHandler {
this.fail();
}
}
protected onPointerRemove(event: AdaptedEvent): void {
protected onPointerRemove(
event: AdaptedEvent,
sourceEvent?: TouchEvent | PointerEvent
): void {
if (sourceEvent?.cancelable) {
sourceEvent.preventDefault();
}

super.onPointerRemove(event);
this.tracker.removeFromTracker(event.pointerId);

Expand All @@ -290,7 +304,22 @@ export default class PanGestureHandler extends GestureHandler {
}
}

protected onPointerMove(event: AdaptedEvent): void {
protected onPointerMove(
event: AdaptedEvent,
sourceEvent?: TouchEvent | PointerEvent
): void {
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);

this.lastX = this.tracker.getLastAvgX();
Expand All @@ -303,11 +332,26 @@ export default class PanGestureHandler extends GestureHandler {
super.onPointerMove(event);
}

protected onPointerOutOfBounds(event: AdaptedEvent): void {
protected onPointerOutOfBounds(
event: AdaptedEvent,
sourceEvent?: TouchEvent | PointerEvent
): void {
if (this.getShouldCancelWhenOutside()) {
return;
}

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);

this.lastX = this.tracker.getLastAvgX();
Expand Down Expand Up @@ -470,6 +514,10 @@ export default class PanGestureHandler extends GestureHandler {
super.activate(force);
}

public fail(_sendIfDisabled?: boolean): void {
super.fail();
}

protected onCancel(): void {
this.clearActivationTimeout();
}
Expand Down
24 changes: 22 additions & 2 deletions src/web/handlers/PinchGestureHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 20 additions & 2 deletions src/web/handlers/RotationGestureHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand Down
Loading
Loading