Skip to content

Commit

Permalink
Add check when removing handlers from orchestrator (#2831)
Browse files Browse the repository at this point in the history
## Description

#2819 removed changes made in #2802. After further investigation we found out that `removeHandlerFromOrchestrator` didn't check if handlers were present in orchestrator, therefore in some situation calling this function ended up in removing wrong handler. Calling `indexOf` returned `-1` and, as you can read in [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice):

> Negative index counts back from the end of the array

So instead of ignoring that, we simply removed wrong handler.

## Test plan

Tested on example app (mostly on swipeable example) and example code from #2819
  • Loading branch information
m-bert committed Mar 26, 2024
1 parent b358207 commit f4f1907
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/web/tools/GestureHandlerOrchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,17 @@ export default class GestureHandlerOrchestrator {
}

public removeHandlerFromOrchestrator(handler: IGestureHandler): void {
this.gestureHandlers.splice(this.gestureHandlers.indexOf(handler), 1);
this.awaitingHandlers.splice(this.awaitingHandlers.indexOf(handler), 1);
this.awaitingHandlersTags.delete(handler.getTag());
const indexInGestureHandlers = this.gestureHandlers.indexOf(handler);
const indexInAwaitingHandlers = this.awaitingHandlers.indexOf(handler);

if (indexInGestureHandlers >= 0) {
this.gestureHandlers.splice(indexInGestureHandlers, 1);
}

if (indexInAwaitingHandlers >= 0) {
this.awaitingHandlers.splice(indexInAwaitingHandlers, 1);
this.awaitingHandlersTags.delete(handler.getTag());
}
}

private cleanupFinishedHandlers(): void {
Expand Down

0 comments on commit f4f1907

Please sign in to comment.