Skip to content

Commit 86046bd

Browse files
committed
first refactor
1 parent d782c95 commit 86046bd

File tree

6 files changed

+25
-16
lines changed

6 files changed

+25
-16
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export default {
6767
},
6868
detachGestureHandler(handlerTag: number) {
6969
shouldPreventDrop = false;
70-
NodeManager.getHandler(handlerTag).detachHtml();
70+
NodeManager.getHandler(handlerTag).detach();
7171
},
7272
updateGestureHandler(handlerTag: number, newConfig: Config) {
7373
NodeManager.getHandler(handlerTag).updateGestureConfig(newConfig);
@@ -84,6 +84,7 @@ export default {
8484
if (shouldPreventDrop) {
8585
return;
8686
}
87+
8788
NodeManager.dropGestureHandler(handlerTag);
8889
},
8990
// eslint-disable-next-line @typescript-eslint/no-empty-function

packages/react-native-gesture-handler/src/v3/HostGestureDetector.web.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,45 @@
11
import { useEffect, useRef } from 'react';
22
import { View } from 'react-native';
3-
import RNGestureHandlerModuleWeb from '../RNGestureHandlerModule.web';
3+
import RNGestureHandlerModule from '../RNGestureHandlerModule.web';
44
import { ActionType } from '../ActionType';
55
export interface GestureHandlerDetectorProps {
66
handlerTags: number[];
77
dispatchesAnimatedEvents: boolean;
88
moduleId: number;
99
children?: React.ReactNode;
10+
actionType?: ActionType;
1011
}
1112

1213
const HostGestureDetector = (props: GestureHandlerDetectorProps) => {
13-
const { handlerTags, children } = props;
14+
const {
15+
handlerTags,
16+
children,
17+
actionType = ActionType.NATIVE_DETECTOR,
18+
} = props;
1419

1520
const viewRef = useRef(null);
1621
const propsRef = useRef<GestureHandlerDetectorProps>(props);
1722
const oldHandlerTags = useRef<Set<number>>(new Set<number>());
1823

19-
const attachHandlers = (): void => {
24+
const attachHandlers = () => {
2025
const currentHandlerTags = new Set(handlerTags);
21-
const newHandlerTags: Set<number> = currentHandlerTags.difference(
26+
const newHandlerTags = currentHandlerTags.difference(
2227
oldHandlerTags.current
2328
);
2429
newHandlerTags.forEach((tag) => {
25-
RNGestureHandlerModuleWeb.attachGestureHandler(
30+
RNGestureHandlerModule.attachGestureHandler(
2631
tag,
2732
viewRef.current,
28-
ActionType.NATIVE_DETECTOR,
33+
actionType,
2934
propsRef
3035
);
3136
});
3237
oldHandlerTags.current = currentHandlerTags;
3338
};
3439

35-
const detachHandlers = (): void => {
40+
const detachHandlers = () => {
3641
handlerTags.forEach((tag) => {
37-
RNGestureHandlerModuleWeb.detachGestureHandler(tag);
42+
RNGestureHandlerModule.detachGestureHandler(tag);
3843
});
3944
};
4045

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ export default abstract class GestureHandler implements IGestureHandler {
7171
this.delegate.init(viewRef, this);
7272
}
7373

74-
public detachHtml() {
74+
public detach() {
7575
this.propsRef = null;
7676
this.viewRef = null;
7777
this.actionType = null;
7878
this.state = State.UNDETERMINED;
7979

80-
this.delegate.detachHtml();
80+
this.delegate.detach();
8181
}
8282

8383
public attachEventManager(manager: EventManager<unknown>): void {
@@ -396,7 +396,7 @@ export default abstract class GestureHandler implements IGestureHandler {
396396
if (this.state === State.ACTIVE) {
397397
resultEvent.nativeEvent.oldState = undefined;
398398
if (
399-
this.actionType === ActionType.NATIVE_DETECTOR ||
399+
this.actionType === ActionType.NATIVE_ANIMATED_EVENT ||
400400
this.actionType === ActionType.NATIVE_DETECTOR_ANIMATED_EVENT
401401
) {
402402
invokeNullableMethod(onGestureHandlerAnimatedEvent, resultEvent);
@@ -524,14 +524,17 @@ export default abstract class GestureHandler implements IGestureHandler {
524524
}
525525

526526
private cancelTouches(): void {
527+
if (!this.propsRef) {
528+
return;
529+
}
527530
const rect = this.delegate.measureView();
528531

529532
const all: PointerData[] = [];
530533
const changed: PointerData[] = [];
531534

532535
const trackerData = this.tracker.trackedPointers;
533536

534-
if (trackerData.size === 0 || !this.propsRef) {
537+
if (trackerData.size === 0) {
535538
return;
536539
}
537540

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default interface IGestureHandler {
3535
cancel: () => void;
3636

3737
reset: () => void;
38-
detachHtml: () => void;
38+
detach: () => void;
3939

4040
shouldWaitForHandlerFailure: (handler: IGestureHandler) => boolean;
4141
shouldRequireToWaitForFailure: (handler: IGestureHandler) => boolean;

packages/react-native-gesture-handler/src/web/tools/GestureHandlerDelegate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export interface GestureHandlerDelegate<TComponent, THandler> {
1111
view: TComponent;
1212

1313
init(viewRef: number, handler: THandler): void;
14-
detachHtml(): void;
14+
detach(): void;
1515
isPointerInBounds({ x, y }: { x: number; y: number }): boolean;
1616
measureView(): MeasureResult;
1717
reset(): void;

packages/react-native-gesture-handler/src/web/tools/GestureHandlerWebDelegate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class GestureHandlerWebDelegate
6363
);
6464
}
6565

66-
detachHtml(): void {
66+
detach(): void {
6767
this.view = null as unknown as HTMLElement;
6868
this.defaultViewStyles = {
6969
userSelect: '',

0 commit comments

Comments
 (0)