Skip to content

Commit 97f6df9

Browse files
authored
Change order of sending touch events and assigning new state (#2261)
## Description This PR makes small change in `moveToState` method. Some handlers require `TouchEvents` to work. These events are not connected with state management system, unless we are talking about `ManualGestureHandler`. Right now example with this handler throws "Maximum call stack size exceeded". Stack trace points out, that the problem originates in `onCancelTouches` method. What is happening, is that each `GestureHandler` in `moveToState` method calls `cancelTouches`, which triggers `onTouchesCancelled`. This happens, if new state will be finished (i.e. `end/failed/cancelled`). When order is not flipped, after calling `cancelTouches`, state manager calls `fail` method, which one more time triggers `moveToState`. We end up with this loop: `fail() -> moveToState() -> cancelTouches() -> fail() ...`. `Fail` method checks if current handler state is `active` or `began`, however without flipping order, `fail` is being called while handler is still in `active` state. When we flip order, `cancelTouches` is called when handler is in `end` state - that prevents falling into endless loop. ## Test plan Tested on example app
1 parent 412f719 commit 97f6df9

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/web/handlers/GestureHandler.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,17 @@ export default abstract class GestureHandler {
121121
return;
122122
}
123123

124+
const oldState = this.currentState;
125+
this.currentState = newState;
126+
124127
if (
125128
this.tracker.getTrackedPointersCount() > 0 &&
126129
this.config.needsPointerData &&
127-
(newState === State.END ||
128-
newState === State.CANCELLED ||
129-
newState === State.FAILED)
130+
this.isFinished()
130131
) {
131132
this.cancelTouches();
132133
}
133134

134-
const oldState = this.currentState;
135-
this.currentState = newState;
136-
137135
GestureHandlerOrchestrator.getInstance().onHandlerStateChange(
138136
this,
139137
newState,
@@ -775,6 +773,14 @@ export default abstract class GestureHandler {
775773
return this.enabled;
776774
}
777775

776+
private isFinished(): boolean {
777+
return (
778+
this.currentState === State.END ||
779+
this.currentState === State.FAILED ||
780+
this.currentState === State.CANCELLED
781+
);
782+
}
783+
778784
protected setShouldCancelWhenOutside(shouldCancel: boolean) {
779785
this.shouldCancellWhenOutside = shouldCancel;
780786
}

0 commit comments

Comments
 (0)