Skip to content

Commit 2ba053a

Browse files
committed
helper action type functions
1 parent e193ff4 commit 2ba053a

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

packages/react-native-gesture-handler/src/ActionType.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,19 @@ export const ActionType = {
77
NATIVE_DETECTOR_ANIMATED_EVENT: 6,
88
} as const;
99

10+
export function isNativeDetectorActionType(type: ActionType | null): boolean {
11+
return (
12+
type === ActionType.NATIVE_ANIMATED_EVENT ||
13+
type === ActionType.NATIVE_DETECTOR_ANIMATED_EVENT
14+
);
15+
}
16+
17+
export function isAnimatedActionType(type: ActionType | null): boolean {
18+
return (
19+
type === ActionType.NATIVE_DETECTOR ||
20+
type === ActionType.NATIVE_DETECTOR_ANIMATED_EVENT
21+
);
22+
}
23+
1024
// eslint-disable-next-line @typescript-eslint/no-redeclare -- backward compatibility; it can be used as a type and as a value
1125
export type ActionType = (typeof ActionType)[keyof typeof ActionType];

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ import IGestureHandler from './IGestureHandler';
1818
import { MouseButton } from '../../handlers/gestureHandlerCommon';
1919
import { PointerType } from '../../PointerType';
2020
import { GestureHandlerDelegate } from '../tools/GestureHandlerDelegate';
21-
import { ActionType } from '../../ActionType';
21+
import {
22+
ActionType,
23+
isAnimatedActionType,
24+
isNativeDetectorActionType,
25+
} from '../../ActionType';
2226
import { tagMessage } from '../../utils';
2327

2428
export default abstract class GestureHandler implements IGestureHandler {
@@ -369,8 +373,7 @@ export default abstract class GestureHandler implements IGestureHandler {
369373
if (touchEvent) {
370374
if (
371375
onGestureHandlerTouchEvent &&
372-
(this.actionType === ActionType.NATIVE_DETECTOR ||
373-
this.actionType === ActionType.NATIVE_DETECTOR_ANIMATED_EVENT)
376+
isNativeDetectorActionType(this.actionType)
374377
) {
375378
invokeNullableMethod(onGestureHandlerTouchEvent, touchEvent);
376379
}
@@ -411,8 +414,7 @@ export default abstract class GestureHandler implements IGestureHandler {
411414
resultEvent.nativeEvent.oldState = undefined;
412415
if (
413416
onGestureHandlerAnimatedEvent &&
414-
(this.actionType === ActionType.NATIVE_ANIMATED_EVENT ||
415-
this.actionType === ActionType.NATIVE_DETECTOR_ANIMATED_EVENT)
417+
isAnimatedActionType(this.actionType)
416418
) {
417419
invokeNullableMethod(onGestureHandlerAnimatedEvent, resultEvent);
418420
}

0 commit comments

Comments
 (0)