Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import React from 'react';

import type { Config, PropsRef } from './web/interfaces';
import type { ActionType } from './ActionType';
import { GestureHandlerWebDelegate } from './web/tools/GestureHandlerWebDelegate';
import type { GestureRelations } from './v3/types';
import { Gestures } from './web/Gestures';
import type { Config, PropsRef } from './web/interfaces';
import InteractionManager from './web/tools/InteractionManager';
import NodeManager from './web/tools/NodeManager';
import { GestureHandlerWebDelegate } from './web/tools/GestureHandlerWebDelegate';
import { GestureRelations } from './v3/types';
import React from 'react';

// init method is called inside attachGestureHandler function. However, this function may
// fail when received view is not valid HTML element. On the other hand, dropGestureHandler
Expand Down Expand Up @@ -54,7 +53,7 @@
}

// @ts-ignore Types should be HTMLElement or React.Component
NodeManager.getHandler(handlerTag).init(newView, propsRef, actionType);

Check warning on line 56 in packages/react-native-gesture-handler/src/RNGestureHandlerModule.web.ts

View workflow job for this annotation

GitHub Actions / check

Unsafe call of an `any` typed value
},
detachGestureHandler(handlerTag: number) {
if (shouldPreventDrop) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import React from 'react';

import { ActionType } from './ActionType';

// GestureHandlers
import PanGestureHandler from './web/handlers/PanGestureHandler';
import TapGestureHandler from './web/handlers/TapGestureHandler';
import type { ActionType } from './ActionType';
import type { Config } from './web/interfaces';
import FlingGestureHandler from './web/handlers/FlingGestureHandler';
import LongPressGestureHandler from './web/handlers/LongPressGestureHandler';
import ManualGestureHandler from './web/handlers/ManualGestureHandler';
import NativeViewGestureHandler from './web/handlers/NativeViewGestureHandler';
import PanGestureHandler from './web/handlers/PanGestureHandler';
import PinchGestureHandler from './web/handlers/PinchGestureHandler';
import type React from 'react';
import RotationGestureHandler from './web/handlers/RotationGestureHandler';
import FlingGestureHandler from './web/handlers/FlingGestureHandler';
import NativeViewGestureHandler from './web/handlers/NativeViewGestureHandler';
import ManualGestureHandler from './web/handlers/ManualGestureHandler';
import { Config } from './web/interfaces';
import TapGestureHandler from './web/handlers/TapGestureHandler';

export const Gestures = {
NativeViewGestureHandler,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import React from 'react';
import { render, cleanup } from '@testing-library/react-native';
import {
Gesture,
GestureDetector,
GestureHandlerRootView,
InterceptingGestureDetector,
useTapGesture,
} from '../index';
import { findNodeHandle, View } from 'react-native';
import { View, findNodeHandle } from 'react-native';
import { cleanup, render } from '@testing-library/react-native';
import React from 'react';
import { VirtualDetector } from '../v3/detectors/VirtualDetector/VirtualDetector';

jest.mock('react-native-worklets', () =>
require('react-native-worklets/src/mock')

Check warning on line 14 in packages/react-native-gesture-handler/src/__tests__/Errors.test.tsx

View workflow job for this annotation

GitHub Actions / check

Unsafe return of an `any` typed value
);

beforeEach(() => cleanup());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
// Disabling lint for assymetric matchers, check proposal below
// https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/56937
import React from 'react';
import { render, cleanup } from '@testing-library/react-native';
import { Text } from 'react-native';
import {
GestureHandlerRootView,
PanGestureHandler,
Gesture,
GestureDetector,
GestureHandlerRootView,
State,
} from '../index';
import type {
LegacyPanGesture,
LegacyTapGesture,
PanGestureHandler,
} from '../index';
import { cleanup, render } from '@testing-library/react-native';
import { fireGestureHandler, getByGestureTestId } from '../jestUtils';
import React from 'react';
import { Text } from 'react-native';

beforeEach(cleanup);

Expand Down Expand Up @@ -166,10 +168,10 @@
]);

if (lastState === State.END) {
expect(panHandlers.end).toHaveBeenCalled();

Check warning on line 171 in packages/react-native-gesture-handler/src/__tests__/Events.test.tsx

View workflow job for this annotation

GitHub Actions / check

Avoid calling `expect` conditionally`
} else {
expect(panHandlers.finish).toHaveBeenCalledWith(

Check warning on line 173 in packages/react-native-gesture-handler/src/__tests__/Events.test.tsx

View workflow job for this annotation

GitHub Actions / check

Avoid calling `expect` conditionally`
expect.any(Object),

Check warning on line 174 in packages/react-native-gesture-handler/src/__tests__/Events.test.tsx

View workflow job for this annotation

GitHub Actions / check

Avoid calling `expect` conditionally`
false
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { tagMessage } from '../utils';
import {
useExclusiveGestures,
useCompetingGestures,
useExclusiveGestures,
useSimultaneousGestures,
} from '../v3/hooks/composition';
import { useGesture } from '../v3/hooks/useGesture';
import type { SingleGesture } from '../v3/types';
import { SingleGestureName } from '../v3/types';
import { configureRelations } from '../v3/detectors/utils';
import { SingleGesture, SingleGestureName } from '../v3/types';
import { renderHook } from '@testing-library/react-native';
import { tagMessage } from '../utils';
import { useGesture } from '../v3/hooks/useGesture';

type AnySingleGesture = SingleGesture<unknown, unknown, unknown>;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { usePanGesture } from '../v3/hooks/gestures';
import { render, renderHook } from '@testing-library/react-native';
import { RectButton, Touchable } from '../v3/components';
import { fireGestureHandler, getByGestureTestId } from '../jestUtils';
import { State } from '../State';
import { render, renderHook } from '@testing-library/react-native';
import GestureHandlerRootView from '../components/GestureHandlerRootView';
import { RectButton, Touchable } from '../v3/components';
import { act } from 'react';
import type { SingleGesture } from '../v3/types';
import { State } from '../State';
import { act } from 'react';
import { usePanGesture } from '../v3/hooks/gestures';

describe('[API v3] Hooks', () => {
test('Pan gesture', () => {
Expand All @@ -15,8 +15,8 @@
const panGesture = renderHook(() =>
usePanGesture({
disableReanimated: true,
onBegin: (e) => onBegin(e),

Check warning on line 18 in packages/react-native-gesture-handler/src/__tests__/api_v3.test.tsx

View workflow job for this annotation

GitHub Actions / check

Unsafe return of an `any` typed value
onActivate: (e) => onStart(e),

Check warning on line 19 in packages/react-native-gesture-handler/src/__tests__/api_v3.test.tsx

View workflow job for this annotation

GitHub Actions / check

Unsafe return of an `any` typed value
})
).result.current;

Expand Down Expand Up @@ -152,8 +152,8 @@
render(<Example />);

const gesture = getByGestureTestId('touchable') as SingleGesture<
any,

Check warning on line 155 in packages/react-native-gesture-handler/src/__tests__/api_v3.test.tsx

View workflow job for this annotation

GitHub Actions / check

Unexpected any. Specify a different type
any,

Check warning on line 156 in packages/react-native-gesture-handler/src/__tests__/api_v3.test.tsx

View workflow job for this annotation

GitHub Actions / check

Unexpected any. Specify a different type
any
>;
const { jsEventHandler } = gesture.detectorCallbacks;
Expand Down
21 changes: 8 additions & 13 deletions packages/react-native-gesture-handler/src/__tests__/mocks.test.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
import React from 'react';
import { Text } from 'react-native';
import { render, fireEvent } from '@testing-library/react-native';

import {
LegacyRawButton,
LegacyBaseButton,
LegacyRectButton,
LegacyBorderlessButton,
LegacyPureNativeButton,
LegacyRawButton,
LegacyRectButton,
} from '../mocks/GestureButtons';

import {
LegacyScrollView,
LegacyFlatList,
LegacyRefreshControl,
LegacyScrollView,
LegacySwitch,
LegacyTextInput,
LegacyRefreshControl,
} from '../mocks/gestureComponents';

import {
TouchableHighlight,
TouchableNativeFeedback,
TouchableOpacity,
TouchableWithoutFeedback,
} from '../mocks/Touchables';

import LegacyPressable from '../mocks/Pressable';

import { fireEvent, render } from '@testing-library/react-native';
import GestureHandlerRootView from '../components/GestureHandlerRootView';
import LegacyPressable from '../mocks/Pressable';
import React from 'react';
import { Text } from 'react-native';
import { Touchable } from '../v3/components';

describe('Jest mocks – legacy components render without crashing', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import * as React from 'react';
import { Animated, Platform, StyleSheet } from 'react-native';

import createNativeWrapper from '../handlers/createNativeWrapper';
import GestureHandlerButton from './GestureHandlerButton';
import { State } from '../State';

import {
GestureEvent,
HandlerStateChangeEvent,
} from '../handlers/gestureHandlerCommon';
import type { NativeViewGestureHandlerPayload } from '../handlers/GestureHandlerEventPayload';
import type {
BaseButtonWithRefProps,
LegacyBaseButtonProps,
RectButtonWithRefProps,
LegacyRectButtonProps,
BorderlessButtonWithRefProps,
LegacyBaseButtonProps,
LegacyBorderlessButtonProps,
LegacyRawButtonProps,
LegacyRectButtonProps,
RectButtonWithRefProps,
} from './GestureButtonsProps';
import type {
GestureEvent,
HandlerStateChangeEvent,
} from '../handlers/gestureHandlerCommon';
import GestureHandlerButton from './GestureHandlerButton';
import type { HostComponent } from 'react-native';
import type { NativeViewGestureHandlerPayload } from '../handlers/GestureHandlerEventPayload';
import { State } from '../State';
import createNativeWrapper from '../handlers/createNativeWrapper';

/**
* @deprecated use `RawButton` instead
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import {
import type * as React from 'react';
import type {
AccessibilityProps,
ColorValue,
LayoutChangeEvent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
import * as React from 'react';
import {
PropsWithChildren,
import type {
ForwardedRef,
RefAttributes,
PropsWithChildren,
ReactElement,
RefAttributes,
} from 'react';
import {
DrawerLayoutAndroid as RNDrawerLayoutAndroid,
FlatList as RNFlatList,
RefreshControl as RNRefreshControl,
ScrollView as RNScrollView,
ScrollViewProps as RNScrollViewProps,
Switch as RNSwitch,
SwitchProps as RNSwitchProps,
TextInput as RNTextInput,
TextInputProps as RNTextInputProps,
DrawerLayoutAndroid as RNDrawerLayoutAndroid,
} from 'react-native';
import type {
DrawerLayoutAndroidProps as RNDrawerLayoutAndroidProps,
FlatList as RNFlatList,
FlatListProps as RNFlatListProps,
RefreshControl as RNRefreshControl,
ScrollViewProps as RNScrollViewProps,
SwitchProps as RNSwitchProps,
TextInputProps as RNTextInputProps,
} from 'react-native';

import type { NativeViewGestureHandlerProps } from '../handlers/NativeViewGestureHandler';
import createNativeWrapper from '../handlers/createNativeWrapper';

import {
NativeViewGestureHandlerProps,
nativeViewProps,
} from '../handlers/NativeViewGestureHandler';

import { nativeViewProps } from '../handlers/NativeViewGestureHandler';
import { toArray } from '../utils';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import * as React from 'react';
import {
FlatList as RNFlatList,
ScrollView as RNScrollView,
Switch as RNSwitch,
TextInput as RNTextInput,
ScrollView as RNScrollView,
FlatListProps,
View,
} from 'react-native';

import type { FlatListProps } from 'react-native';
import createNativeWrapper from '../handlers/createNativeWrapper';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {
import type {
AccessibilityProps,
ColorValue,
HostComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import { ColorValue, View, ViewProps } from 'react-native';
import type { ColorValue, ViewProps } from 'react-native';
import { View } from 'react-native';

type ButtonProps = ViewProps & {
ref?: React.Ref<React.ComponentRef<typeof View>>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as React from 'react';
import { PropsWithChildren } from 'react';
import { StyleSheet } from 'react-native';
import GestureHandlerRootViewContext from '../GestureHandlerRootViewContext';
import type { RootViewNativeProps } from '../specs/RNGestureHandlerRootViewNativeComponent';
import GestureHandlerRootViewNativeComponent from '../specs/RNGestureHandlerRootViewNativeComponent';
import type { PropsWithChildren } from 'react';
import type { RootViewNativeProps } from '../specs/RNGestureHandlerRootViewNativeComponent';
import { StyleSheet } from 'react-native';

export interface GestureHandlerRootViewProps
extends PropsWithChildren<RootViewNativeProps> {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { PropsWithChildren } from 'react';
import { View, StyleSheet } from 'react-native';
import { StyleSheet, View } from 'react-native';
import GestureHandlerRootViewContext from '../GestureHandlerRootViewContext';
import type { PropsWithChildren } from 'react';
import type { RootViewNativeProps } from '../specs/RNGestureHandlerRootViewNativeComponent';

export interface GestureHandlerRootViewProps
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as React from 'react';
import { PropsWithChildren } from 'react';
import { View, ViewProps, StyleSheet } from 'react-native';
import { StyleSheet, View } from 'react-native';
import GestureHandlerRootViewContext from '../GestureHandlerRootViewContext';
import type { PropsWithChildren } from 'react';
import type { ViewProps } from 'react-native';

export interface GestureHandlerRootViewProps
extends PropsWithChildren<ViewProps> {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,38 @@
import { INT32_MAX, isTestEnv } from '../../utils';
import type {
Insets,
LayoutChangeEvent,
StyleProp,
ViewStyle,
} from 'react-native';
import type {
LegacyPressableProps,
PressableDimensions,
PressableEvent,
} from './PressableProps';
import React, {
useCallback,
useEffect,
useMemo,
useRef,
useState,
} from 'react';
import { GestureObjects as Gesture } from '../../handlers/gestures/gestureObjects';
import { GestureDetector } from '../../handlers/gestures/GestureDetector';
import {
PressableEvent,
PressableDimensions,
LegacyPressableProps,
} from './PressableProps';
import type { RelationPropName, RelationPropType } from '../utils';
import { StateMachineEvent, getStatesConfig } from './stateDefinitions';
import {
Insets,
LayoutChangeEvent,
Platform,
StyleProp,
ViewStyle,
} from 'react-native';
import { ButtonComponent as NativeButton } from '../GestureHandlerButton';
import {
gestureToPressableEvent,
addInsets,
numberAsInset,
gestureToPressableEvent,
gestureTouchToPressableEvent,
isTouchWithinInset,
numberAsInset,
} from './utils';
import { GestureObjects as Gesture } from '../../handlers/gestures/gestureObjects';
import { GestureDetector } from '../../handlers/gestures/GestureDetector';
import { ButtonComponent as NativeButton } from '../GestureHandlerButton';
import { Platform } from 'react-native';
import { PressabilityDebugView } from '../../handlers/PressabilityDebugView';
import { INT32_MAX, isTestEnv } from '../../utils';
import {
applyRelationProp,
RelationPropName,
RelationPropType,
} from '../utils';
import { getStatesConfig, StateMachineEvent } from './stateDefinitions';
import { PressableStateMachine } from './StateMachine';
import { applyRelationProp } from '../utils';
import { useIsScreenReaderEnabled } from '../../useIsScreenReaderEnabled';

const DEFAULT_LONG_PRESS_DURATION = 500;
Expand Down
Loading
Loading