Skip to content

Commit 1d96fa1

Browse files
committed
Merge branch 'next' into @akwasniewski/logic-detector
2 parents 832a039 + ee6107f commit 1d96fa1

File tree

3 files changed

+72
-25
lines changed

3 files changed

+72
-25
lines changed

packages/react-native-gesture-handler/src/handlers/gestures/GestureDetector/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,5 +175,8 @@ export function useWebEventHandlers() {
175175
onGestureHandlerStateChange: (e: ResultEvent) => {
176176
onGestureHandlerEvent(e.nativeEvent as GestureHandlerNativeEvent);
177177
},
178+
onGestureHandlerTouchEvent: () => {
179+
// no-op
180+
},
178181
});
179182
}

packages/react-native-gesture-handler/src/web/handlers/GestureHandler.ts

Lines changed: 63 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ export default abstract class GestureHandler implements IGestureHandler {
4040
private viewRef: number | null = null;
4141
private propsRef: React.RefObject<PropsRef> | null = null;
4242
private actionType: ActionType | null = null;
43-
private dispatchesAnimatedEvents: boolean = false;
43+
private forAnimated: boolean = false;
44+
private forReanimated: boolean = false;
4445
private _handlerTag!: number;
4546

4647
private hitSlop?: HitSlop = undefined;
@@ -97,7 +98,8 @@ export default abstract class GestureHandler implements IGestureHandler {
9798
this.viewRef = null;
9899
this.actionType = null;
99100
this.state = State.UNDETERMINED;
100-
this.dispatchesAnimatedEvents = false;
101+
this.forAnimated = false;
102+
this.forReanimated = false;
101103

102104
this.delegate.detach();
103105
}
@@ -381,21 +383,28 @@ export default abstract class GestureHandler implements IGestureHandler {
381383
return;
382384
}
383385
this.ensurePropsRef();
384-
const { onGestureHandlerEvent, onGestureHandlerTouchEvent }: PropsRef =
385-
this.propsRef!.current;
386+
const {
387+
onGestureHandlerEvent,
388+
onGestureHandlerTouchEvent,
389+
onGestureHandlerReanimatedTouchEvent,
390+
}: PropsRef = this.propsRef!.current;
386391

387392
const touchEvent: ResultEvent<GestureTouchEvent> | undefined =
388393
this.transformTouchEvent(event);
389394

390-
if (touchEvent) {
391-
if (
392-
onGestureHandlerTouchEvent &&
393-
usesNativeOrLogicDetector(this.actionType)
394-
) {
395-
invokeNullableMethod(onGestureHandlerTouchEvent, touchEvent);
396-
} else {
397-
invokeNullableMethod(onGestureHandlerEvent, touchEvent);
398-
}
395+
if (!touchEvent) {
396+
return;
397+
}
398+
399+
if (usesNativeOrLogicDetector(this.actionType)) {
400+
invokeNullableMethod(
401+
this.forReanimated
402+
? onGestureHandlerReanimatedTouchEvent
403+
: onGestureHandlerTouchEvent,
404+
touchEvent
405+
);
406+
} else {
407+
invokeNullableMethod(onGestureHandlerEvent, touchEvent);
399408
}
400409
}
401410

@@ -408,6 +417,8 @@ export default abstract class GestureHandler implements IGestureHandler {
408417
onGestureHandlerEvent,
409418
onGestureHandlerStateChange,
410419
onGestureHandlerAnimatedEvent,
420+
onGestureHandlerReanimatedEvent,
421+
onGestureHandlerReanimatedStateChange,
411422
}: PropsRef = this.propsRef!.current;
412423

413424
const resultEvent: ResultEvent = !usesNativeOrLogicDetector(this.actionType)
@@ -422,18 +433,27 @@ export default abstract class GestureHandler implements IGestureHandler {
422433
// However, this may cause trouble in the future (but for now we don't know that)
423434
if (this.lastSentState !== newState) {
424435
this.lastSentState = newState;
425-
invokeNullableMethod(onGestureHandlerStateChange, resultEvent);
436+
invokeNullableMethod(
437+
this.forReanimated
438+
? onGestureHandlerReanimatedStateChange
439+
: onGestureHandlerStateChange,
440+
resultEvent
441+
);
426442
}
427443
if (this.state === State.ACTIVE) {
428444
if (!usesNativeOrLogicDetector(this.actionType)) {
429445
(resultEvent.nativeEvent as GestureHandlerNativeEvent).oldState =
430446
undefined;
431447
}
432-
if (onGestureHandlerAnimatedEvent && this.dispatchesAnimatedEvents) {
433-
invokeNullableMethod(onGestureHandlerAnimatedEvent, resultEvent);
434-
}
435448

436-
invokeNullableMethod(onGestureHandlerEvent, resultEvent);
449+
invokeNullableMethod(
450+
this.forReanimated
451+
? onGestureHandlerReanimatedEvent
452+
: this.forAnimated
453+
? onGestureHandlerAnimatedEvent
454+
: onGestureHandlerEvent,
455+
resultEvent
456+
);
437457
}
438458
};
439459

@@ -638,9 +658,22 @@ export default abstract class GestureHandler implements IGestureHandler {
638658
timeStamp: Date.now(),
639659
};
640660

641-
const { onGestureHandlerEvent }: PropsRef = this.propsRef!.current;
661+
const {
662+
onGestureHandlerEvent,
663+
onGestureHandlerReanimatedTouchEvent,
664+
onGestureHandlerTouchEvent,
665+
}: PropsRef = this.propsRef!.current;
642666

643-
invokeNullableMethod(onGestureHandlerEvent, cancelEvent);
667+
if (this.actionType === ActionType.NATIVE_DETECTOR) {
668+
invokeNullableMethod(
669+
this.forReanimated
670+
? onGestureHandlerReanimatedTouchEvent
671+
: onGestureHandlerTouchEvent,
672+
cancelEvent
673+
);
674+
} else {
675+
invokeNullableMethod(onGestureHandlerEvent, cancelEvent);
676+
}
644677
}
645678

646679
private ensurePropsRef(): void {
@@ -692,7 +725,11 @@ export default abstract class GestureHandler implements IGestureHandler {
692725
}
693726

694727
if (config.dispatchesAnimatedEvents !== undefined) {
695-
this.dispatchesAnimatedEvents = config.dispatchesAnimatedEvents;
728+
this.forAnimated = config.dispatchesAnimatedEvents;
729+
}
730+
731+
if (config.shouldUseReanimated !== undefined) {
732+
this.forReanimated = config.shouldUseReanimated;
696733
}
697734

698735
if (config.manualActivation !== undefined) {
@@ -875,7 +912,8 @@ export default abstract class GestureHandler implements IGestureHandler {
875912
this.mouseButton = undefined;
876913
this.hitSlop = undefined;
877914
this.needsPointerData = false;
878-
this.dispatchesAnimatedEvents = false;
915+
this.forAnimated = false;
916+
this.forReanimated = false;
879917
this.enableContextMenu = false;
880918
this._activeCursor = undefined;
881919
this._touchAction = undefined;
@@ -992,7 +1030,9 @@ function invokeNullableMethod(
9921030
method:
9931031
| ((event: ResultEvent) => void)
9941032
| { __getHandler: () => (event: ResultEvent) => void }
995-
| { __nodeConfig: { argMapping: unknown[] } },
1033+
| { __nodeConfig: { argMapping: unknown[] } }
1034+
| null
1035+
| undefined,
9961036
event: ResultEvent
9971037
): void {
9981038
if (!method) {

packages/react-native-gesture-handler/src/web/interfaces.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export interface Config extends Record<string, ConfigArgs> {
5252
touchAction?: TouchAction;
5353
manualActivation?: boolean;
5454
dispatchesAnimatedEvents?: false;
55+
shouldUseReanimated?: boolean;
5556
needsPointerData?: false;
5657

5758
activateAfterLongPress?: number;
@@ -124,9 +125,12 @@ export interface ResultEvent<T extends ResultEventType = ResultEventType>
124125

125126
export interface PropsRef {
126127
onGestureHandlerEvent: (e: ResultEvent) => void;
127-
onGestureHandlerAnimatedEvent?: (e: ResultEvent) => void;
128128
onGestureHandlerStateChange: (e: ResultEvent) => void;
129-
onGestureHandlerTouchEvent?: (e: ResultEvent) => void;
129+
onGestureHandlerTouchEvent: (e: ResultEvent) => void;
130+
onGestureHandlerReanimatedEvent?: (e: ResultEvent) => void;
131+
onGestureHandlerReanimatedStateChange?: (e: ResultEvent) => void;
132+
onGestureHandlerReanimatedTouchEvent?: (e: ResultEvent) => void;
133+
onGestureHandlerAnimatedEvent?: (e: ResultEvent) => void;
130134
}
131135

132136
export interface AdaptedEvent {

0 commit comments

Comments
 (0)