Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions packages/react-native-gesture-handler/src/ActionType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,3 @@ export const ActionType = {

// eslint-disable-next-line @typescript-eslint/no-redeclare -- backward compatibility; it can be used as a type and as a value
export type ActionType = (typeof ActionType)[keyof typeof ActionType];

export function usesNativeOrVirtualDetector(
actionType: ActionType | null
): boolean {
return (
actionType === ActionType.NATIVE_DETECTOR ||
actionType === ActionType.VIRTUAL_DETECTOR
);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import { ActionType, usesNativeOrVirtualDetector } from '../../ActionType';
import { ActionType } from '../../ActionType';
import type {
ActiveCursor,
GestureTouchEvent,
Expand Down Expand Up @@ -98,6 +98,13 @@ export default abstract class GestureHandler implements IGestureHandler {
this.delegate.init(viewRef, this);
}

public usesNativeOrVirtualDetector(): boolean {
return (
this.actionType === ActionType.NATIVE_DETECTOR ||
this.actionType === ActionType.VIRTUAL_DETECTOR
);
}
Comment thread
m-bert marked this conversation as resolved.

public detach() {
if (this.state === State.ACTIVE) {
this.cancel();
Expand Down Expand Up @@ -413,7 +420,7 @@ export default abstract class GestureHandler implements IGestureHandler {
return;
}

if (!usesNativeOrVirtualDetector(this.actionType)) {
if (!this.usesNativeOrVirtualDetector()) {
onGestureHandlerEvent?.(touchEvent);
return;
}
Expand All @@ -440,9 +447,7 @@ export default abstract class GestureHandler implements IGestureHandler {

const isStateChange = this.lastSentState !== newState;

const resultEvent: ResultEvent = !usesNativeOrVirtualDetector(
this.actionType
)
const resultEvent: ResultEvent = !this.usesNativeOrVirtualDetector()
? this.transformEventData(newState, oldState)
: isStateChange
? this.transformStateChangeEvent(newState, oldState)
Expand All @@ -467,7 +472,7 @@ export default abstract class GestureHandler implements IGestureHandler {
}

// Cover only V3 path due to different event shape
if (!isStateChange && usesNativeOrVirtualDetector(this.actionType)) {
if (!isStateChange && this.usesNativeOrVirtualDetector()) {
const handlerData = (
resultEvent.nativeEvent as GestureUpdateEventWithHandlerData<unknown>
).handlerData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export default interface IGestureHandler {
readonly touchAction?: TouchAction | undefined;
readonly userSelect?: UserSelect | undefined;

usesNativeOrVirtualDetector: () => boolean;

attachEventManager: (manager: EventManager<unknown>) => void;

isButtonInConfig: (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Platform } from 'react-native';

import { type ActionType, usesNativeOrVirtualDetector } from '../../ActionType';
import { type ActionType } from '../../ActionType';
import { State } from '../../State';
import { deepEqual } from '../../utils';
import type { NativeHandlerData } from '../../v3/hooks/gestures/native/NativeTypes';
Expand Down Expand Up @@ -59,7 +59,7 @@ export default class NativeViewGestureHandler extends GestureHandler {

this.restoreViewStyles(view);

if (usesNativeOrVirtualDetector(this.actionType)) {
if (this.usesNativeOrVirtualDetector()) {
this.role =
(view.getAttribute(
NATIVE_GESTURE_ROLE_ATTRIBUTE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ export class GestureHandlerWebDelegate
}

this.gestureHandler = handler;
this.view = findNodeHandle(viewRef) as unknown as HTMLElement;

this.view = handler.usesNativeOrVirtualDetector()
? (viewRef as unknown as HTMLElement)
: (findNodeHandle(viewRef) as unknown as HTMLElement);

this.defaultViewStyles = {
userSelect: this.view.style.userSelect,
Expand Down
Loading