Skip to content
8 changes: 4 additions & 4 deletions apps/common-app/src/new_api/drag_n_drop/Draggable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
PanGestureHandlerEventPayload,
Gesture,
GestureDetector,
PanGesture,
TapGesture,
PanGestureType,
TapGestureType,
} from 'react-native-gesture-handler';
import Animated, { runOnJS, useAnimatedStyle } from 'react-native-reanimated';

Expand All @@ -22,8 +22,8 @@ interface DraggableProps {
isActive: boolean;
translation: AnimatedPostion;
position: { x: number; y: number };
dragGesture: PanGesture;
tapEndGesture: TapGesture;
dragGesture: PanGestureType;
tapEndGesture: TapGestureType;
tileSize: number;
rowGap: number;
columnGap: number;
Expand Down
28 changes: 14 additions & 14 deletions packages/react-native-gesture-handler/src/__tests__/Events.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
Gesture,
GestureDetector,
State,
PanGesture,
TapGesture,
PanGestureType,
TapGestureType,
} from '../index';
import { useAnimatedGestureHandler } from 'react-native-reanimated';
import { fireGestureHandler, getByGestureTestId } from '../jestUtils';
Expand Down Expand Up @@ -300,7 +300,7 @@
<RacingHandlers tapHandlers={tapHandlers} panHandlers={panHandlers} />
);

fireGestureHandler<PanGesture>(getByGestureTestId('pan'), [
fireGestureHandler<PanGestureType>(getByGestureTestId('pan'), [
{ state: State.BEGAN },
{ state: State.ACTIVE },
{ state: State.END },
Expand All @@ -315,7 +315,7 @@
test('sends events with additional data to handlers', () => {
const panHandlers = mockedEventHandlers();
render(<SingleHandler handlers={panHandlers} treatStartAsUpdate />);
fireGestureHandler<PanGesture>(getByGestureTestId('pan'), [
fireGestureHandler<PanGestureType>(getByGestureTestId('pan'), [
{ state: State.BEGAN, translationX: 0 },
{ state: State.ACTIVE, translationX: 10 },
{ translationX: 20 },
Expand Down Expand Up @@ -358,7 +358,7 @@
const panHandlers = mockedEventHandlers();
render(<SingleHandler handlers={panHandlers} />);
expect(() => {
fireGestureHandler<PanGesture>(getByGestureTestId('pan'), [
fireGestureHandler<PanGestureType>(getByGestureTestId('pan'), [
{ oldState: State.UNDETERMINED, state: State.BEGAN, x: 0, y: 10 },
{ oldState: State.UNDETERMINED, state: State.ACTIVE, x: 1, y: 11 },
]);
Expand All @@ -372,17 +372,17 @@
(lastState) => {
const panHandlers = mockedEventHandlers();
render(<SingleHandler handlers={panHandlers} />);
fireGestureHandler<PanGesture>(getByGestureTestId('pan'), [
fireGestureHandler<PanGestureType>(getByGestureTestId('pan'), [
{ state: State.BEGAN },
{ state: State.ACTIVE },
{ state: lastState },
]);

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

Check warning on line 382 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 384 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 385 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 Expand Up @@ -452,7 +452,7 @@
test('fills missing ACTIVE states', () => {
const panHandlers = mockedEventHandlers();
render(<RacingTapAndPan handlers={panHandlers} treatStartAsUpdate />);
fireGestureHandler<PanGesture>(getByGestureTestId('pan'), [
fireGestureHandler<PanGestureType>(getByGestureTestId('pan'), [
{ state: State.BEGAN, x: 0, y: 10 },
{ state: State.ACTIVE, x: 1, y: 11 },
{ x: 2, y: 12 },
Expand All @@ -469,15 +469,15 @@
test('fills BEGIN and END events for discrete handlers', () => {
const handlers = mockedEventHandlers();
render(<RacingTapAndPan handlers={handlers} treatStartAsUpdate />);
fireGestureHandler<TapGesture>(getByGestureTestId('tap'), [{ x: 5 }]);
fireGestureHandler<TapGestureType>(getByGestureTestId('tap'), [{ x: 5 }]);
expect(handlers.begin).toHaveBeenCalledTimes(1);
expect(handlers.end).toHaveBeenCalledTimes(1);
});

test('with FAILED event, fills BEGIN event for discrete handlers', () => {
const handlers = mockedEventHandlers();
render(<RacingTapAndPan handlers={handlers} treatStartAsUpdate />);
fireGestureHandler<TapGesture>(getByGestureTestId('tap'), [
fireGestureHandler<TapGestureType>(getByGestureTestId('tap'), [
{ state: State.FAILED },
]);
expect(handlers.begin).toHaveBeenCalledTimes(1);
Expand All @@ -488,7 +488,7 @@
test('uses event data from first event in filled BEGIN, ACTIVE events', () => {
const handlers = mockedEventHandlers();
render(<RacingTapAndPan handlers={handlers} treatStartAsUpdate />);
fireGestureHandler<PanGesture>(getByGestureTestId('pan'), [{ x: 120 }]);
fireGestureHandler<PanGestureType>(getByGestureTestId('pan'), [{ x: 120 }]);
expect(handlers.begin).toHaveBeenCalledWith(
expect.objectContaining({ x: 120 })
);
Expand All @@ -501,7 +501,7 @@
test('uses event data from last event in filled END events', () => {
const handlers = mockedEventHandlers();
render(<RacingTapAndPan handlers={handlers} treatStartAsUpdate />);
fireGestureHandler<PanGesture>(getByGestureTestId('pan'), [
fireGestureHandler<PanGestureType>(getByGestureTestId('pan'), [
{ x: 120, state: State.FAILED },
]);
expect(handlers.begin).toHaveBeenCalledTimes(1);
Expand All @@ -515,7 +515,7 @@
test('uses event data filled events', () => {
const handlers = mockedEventHandlers();
render(<RacingTapAndPan handlers={handlers} treatStartAsUpdate />);
fireGestureHandler<PanGesture>(getByGestureTestId('pan'), [
fireGestureHandler<PanGestureType>(getByGestureTestId('pan'), [
{ x: 5, y: 15 },
{ x: 6, y: 16 },
{ x: 7, y: 17 },
Expand All @@ -533,15 +533,15 @@
test("fills BEGIN and END events when they're not present, for discrete handlers", () => {
const handlers = mockedEventHandlers();
render(<RacingTapAndPan handlers={handlers} treatStartAsUpdate />);
fireGestureHandler<TapGesture>(getByGestureTestId('tap'));
fireGestureHandler<TapGestureType>(getByGestureTestId('tap'));
expect(handlers.begin).toHaveBeenCalledTimes(1);
expect(handlers.end).toHaveBeenCalledTimes(1);
});

test("fills BEGIN, ACTIVE and END events when they're not present, for continuous handlers", () => {
const handlers = mockedEventHandlers();
render(<RacingTapAndPan handlers={handlers} treatStartAsUpdate />);
fireGestureHandler<PanGesture>(getByGestureTestId('pan'));
fireGestureHandler<PanGestureType>(getByGestureTestId('pan'));
expect(handlers.begin).toHaveBeenCalledTimes(1);
expect(handlers.active).toHaveBeenCalledTimes(1);
expect(handlers.end).toHaveBeenCalledTimes(1);
Expand Down
27 changes: 14 additions & 13 deletions packages/react-native-gesture-handler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,20 @@ export { default as createNativeWrapper } from './handlers/createNativeWrapper';
export type { NativeViewGestureHandlerProps } from './handlers/NativeViewGestureHandler';
export { GestureDetector } from './handlers/gestures/GestureDetector';
export { GestureObjects as Gesture } from './handlers/gestures/gestureObjects';
export type { TapGestureType as TapGesture } from './handlers/gestures/tapGesture';
export type { PanGestureType as PanGesture } from './handlers/gestures/panGesture';
export type { FlingGestureType as FlingGesture } from './handlers/gestures/flingGesture';
export type { LongPressGestureType as LongPressGesture } from './handlers/gestures/longPressGesture';
export type { PinchGestureType as PinchGesture } from './handlers/gestures/pinchGesture';
export type { RotationGestureType as RotationGesture } from './handlers/gestures/rotationGesture';
export type { ForceTouchGestureType as ForceTouchGesture } from './handlers/gestures/forceTouchGesture';
export type { ManualGestureType as ManualGesture } from './handlers/gestures/manualGesture';
export type { HoverGestureType as HoverGesture } from './handlers/gestures/hoverGesture';
export type { TapGestureType } from './handlers/gestures/tapGesture';
export type { PanGestureType } from './handlers/gestures/panGesture';
export type { FlingGestureType } from './handlers/gestures/flingGesture';
export type { LongPressGestureType } from './handlers/gestures/longPressGesture';
export type { PinchGestureType } from './handlers/gestures/pinchGesture';
export type { RotationGestureType } from './handlers/gestures/rotationGesture';
export type { ForceTouchGestureType } from './handlers/gestures/forceTouchGesture';
export type { ManualGestureType } from './handlers/gestures/manualGesture';
export type { HoverGestureType } from './handlers/gestures/hoverGesture';
export type {
ComposedGestureType as ComposedGesture,
RaceGestureType as RaceGesture,
SimultaneousGestureType as SimultaneousGesture,
ExclusiveGestureType as ExclusiveGesture,
ComposedGestureType,
RaceGestureType,
SimultaneousGestureType,
ExclusiveGestureType,
} from './handlers/gestures/gestureComposition';
export type { GestureStateManagerType as GestureStateManager } from './handlers/gestures/gestureStateManager';
export { NativeViewGestureHandler } from './handlers/NativeViewGestureHandler';
Expand Down Expand Up @@ -170,6 +170,7 @@ export * from './v3/hooks/useGesture';
export * from './v3/hooks/relations';

export { SingleGestureName } from './v3/types';
export type { ComposedGesture } from './v3/types';

export * from './v3/hooks/gestures';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,67 @@
import type { FlingGestureEvent, FlingGesture } from './useFling';
import type { HoverGestureEvent, HoverGesture } from './useHover';
import type { LongPressGestureEvent, LongPressGesture } from './useLongPress';
import type { ManualGestureEvent, ManualGesture } from './useManual';
import type { NativeGestureEvent, NativeGesture } from './useNative';
import type { PanGestureEvent, PanGesture } from './usePan';
import type { PinchGestureEvent, PinchGesture } from './usePinch';
import type { RotationGestureEvent, RotationGesture } from './useRotation';
import type { TapGestureEvent, TapGesture } from './useTap';

export type { TapGestureConfig } from './useTap';
export type { TapGesture, TapGestureEvent };
export { useTap } from './useTap';

export type { FlingGestureConfig } from './useFling';
export type { FlingGesture, FlingGestureEvent };
export { useFling } from './useFling';

export type { LongPressGestureConfig } from './useLongPress';
export type { LongPressGesture, LongPressGestureEvent };
export { useLongPress } from './useLongPress';

export type { PinchGestureConfig } from './usePinch';
export type { PinchGesture, PinchGestureEvent };
export { usePinch } from './usePinch';

export type { RotationGestureConfig } from './useRotation';
export type { RotationGesture, RotationGestureEvent };
export { useRotation } from './useRotation';

export type { HoverGestureConfig } from './useHover';
export type { HoverGesture, HoverGestureEvent };
export { useHover } from './useHover';

export type { ManualGestureConfig } from './useManual';
export type { ManualGesture, ManualGestureEvent };
export { useManual } from './useManual';

export type { NativeViewGestureConfig } from './useNative';
export type { NativeGesture, NativeGestureEvent };
export { useNative } from './useNative';

export type { PanGestureConfig } from './usePan';
export type { PanGesture, PanGestureEvent };
export { usePan } from './usePan';

export type SingleGesture =
| TapGesture
| FlingGesture
| LongPressGesture
| PinchGesture
| RotationGesture
| HoverGesture
| ManualGesture
| NativeGesture
| PanGesture;

export type SingleGestureEvent =
| TapGestureEvent
| FlingGestureEvent
| LongPressGestureEvent
| PinchGestureEvent
| RotationGestureEvent
| HoverGestureEvent
| ManualGestureEvent
| NativeGestureEvent
| PanGestureEvent;
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import {
BaseGestureConfig,
ExcludeInternalConfigProps,
SingleGesture,
SingleGestureName,
WithSharedValue,
GestureStateChangeEvent,
GestureUpdateEvent,
} from '../../types';
import { useGesture } from '../useGesture';
import { cloneConfig } from '../utils';
Expand Down Expand Up @@ -52,3 +55,12 @@ export function useFling(config: FlingGestureConfig) {

return useGesture(SingleGestureName.Fling, flingConfig);
}

export type FlingGestureEvent =
| GestureStateChangeEvent<FlingHandlerData>
| GestureUpdateEvent<FlingHandlerData>;
Comment on lines +59 to +61
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually want to combine these? At the end of the day, those events are accessed in different callbacks


export type FlingGesture = SingleGesture<
FlingHandlerData,
FlingGestureProperties
>;
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import { HoverEffect } from '../../../handlers/gestures/hoverGesture';
import {
BaseGestureConfig,
ExcludeInternalConfigProps,
SingleGesture,
HandlerData,
SingleGestureName,
WithSharedValue,
GestureStateChangeEvent,
GestureUpdateEvent,
} from '../../types';
import { useGesture } from '../useGesture';
import { cloneConfig, getChangeEventCalculator } from '../utils';
Expand Down Expand Up @@ -64,3 +67,12 @@ export function useHover(config: HoverGestureConfig) {

return useGesture(SingleGestureName.Hover, hoverConfig);
}

export type HoverGestureEvent =
| GestureStateChangeEvent<HoverHandlerData>
| GestureUpdateEvent<HoverHandlerData>;

export type HoverGesture = SingleGesture<
HoverHandlerData,
HoverGestureProperties
>;
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import {
BaseGestureConfig,
ExcludeInternalConfigProps,
SingleGesture,
SingleGestureName,
WithSharedValue,
GestureStateChangeEvent,
GestureUpdateEvent,
} from '../../types';
import { useGesture } from '../useGesture';
import { cloneConfig, remapProps } from '../utils';
Expand Down Expand Up @@ -79,3 +82,12 @@ export function useLongPress(config: LongPressGestureConfig) {
longPressConfig
);
}

export type LongPressGestureEvent =
| GestureStateChangeEvent<LongPressHandlerData>
| GestureUpdateEvent<LongPressHandlerData>;

export type LongPressGesture = SingleGesture<
LongPressHandlerData,
LongPressGestureProperties
>;
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import {
BaseGestureConfig,
ExcludeInternalConfigProps,
SingleGesture,
SingleGestureName,
GestureStateChangeEvent,
GestureUpdateEvent,
} from '../../types';

import { useGesture } from '../useGesture';
import { cloneConfig } from '../utils';

Expand All @@ -24,3 +28,12 @@ export function useManual(config: ManualGestureConfig) {

return useGesture(SingleGestureName.Manual, manualConfig);
}

export type ManualGestureEvent =
| GestureStateChangeEvent<ManualHandlerData>
| GestureUpdateEvent<ManualHandlerData>;

export type ManualGesture = SingleGesture<
ManualHandlerData,
ManualGestureProperties
>;
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import {
BaseGestureConfig,
ExcludeInternalConfigProps,
SingleGesture,
SingleGestureName,
WithSharedValue,
GestureStateChangeEvent,
GestureUpdateEvent,
} from '../../types';
import { useGesture } from '../useGesture';
import { cloneConfig } from '../utils';
Expand Down Expand Up @@ -43,3 +46,12 @@ export function useNative(config: NativeViewGestureConfig) {

return useGesture(SingleGestureName.Native, nativeConfig);
}

export type NativeGestureEvent =
| GestureStateChangeEvent<NativeViewHandlerData>
| GestureUpdateEvent<NativeViewHandlerData>;

export type NativeGesture = SingleGesture<
NativeViewHandlerData,
NativeViewGestureProperties
>;
Loading
Loading