Skip to content

Commit a6d83a1

Browse files
j-piaseckim-bert
andauthored
Fix simultaneous gesture when it receives composed gestures as arguments (#2252)
## Description Right now `Simultaneous` gesture transforms received gestures into the array of non-composed gestures (flattening it if necessary) and makes every gesture simultaneous with every gesture in the array. It's not a good approach because `Exclusive` also exists and putting an exclusive gesture into `Simultaneous` meant that gestures meant to be exclusive are now also simultaneous, resulting in different behavior on different platforms. This PR changes the behavior so it respects groups, meaning exclusive gestures will not be made simultaneous with each other. ## Test plan Tested on the example app Co-authored-by: Michał Bert <63123542+Warus15@users.noreply.github.com>
1 parent d22f5ed commit a6d83a1

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/handlers/gestures/gestureComposition.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,24 @@ export class ComposedGesture extends Gesture {
6969

7070
export class SimultaneousGesture extends ComposedGesture {
7171
prepare() {
72-
const simultaneousArray = this.gestures
73-
.flatMap((gesture) => gesture.toGestureArray())
74-
.concat(this.simultaneousGestures);
72+
// this piece of magic works something like this:
73+
// for every gesture in the array
74+
const simultaneousArrays = this.gestures.map((gesture) =>
75+
// we take the array it's in
76+
this.gestures
77+
// and make a copy without it
78+
.filter((x) => x !== gesture)
79+
// then we flatmap the result to get list of raw (not composed) gestures
80+
// this way we don't make the gestures simultaneous with themselves, which is
81+
// important when the gesture is `ExclusiveGesture` - we don't want to make
82+
// exclusive gestures simultaneous
83+
.flatMap((x) => x.toGestureArray())
84+
);
7585

76-
for (const gesture of this.gestures) {
86+
for (let i = 0; i < this.gestures.length; i++) {
7787
this.prepareSingleGesture(
78-
gesture,
79-
simultaneousArray,
88+
this.gestures[i],
89+
simultaneousArrays[i],
8090
this.requireGesturesToFail
8191
);
8292
}
@@ -85,6 +95,8 @@ export class SimultaneousGesture extends ComposedGesture {
8595

8696
export class ExclusiveGesture extends ComposedGesture {
8797
prepare() {
98+
// transforms the array of gestures into array of grouped raw (not composed) gestures
99+
// i.e. [gesture1, gesture2, ComposedGesture(gesture3, gesture4)] -> [[gesture1], [gesture2], [gesture3, gesture4]]
88100
const gestureArrays = this.gestures.map((gesture) =>
89101
gesture.toGestureArray()
90102
);
@@ -98,6 +110,7 @@ export class ExclusiveGesture extends ComposedGesture {
98110
this.requireGesturesToFail.concat(requireToFail)
99111
);
100112

113+
// every group gets to wait for all groups before it
101114
requireToFail = requireToFail.concat(gestureArrays[i]);
102115
}
103116
}

0 commit comments

Comments
 (0)