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
5 changes: 2 additions & 3 deletions apps/basic-example/src/NativeDetector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { Animated, Button, useAnimatedValue } from 'react-native';
import {
GestureHandlerRootView,
NativeDetector,
SingleGestureName,
useGesture,
usePan,
} from 'react-native-gesture-handler';

export default function App() {
Expand All @@ -18,7 +17,7 @@ export default function App() {
}
);

const gesture = useGesture(SingleGestureName.Pan, {
const gesture = usePan({
onUpdate: event,
});

Expand Down
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,
LegacyPanGesture,
LegacyTapGesture,
} 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: LegacyPanGesture;
tapEndGesture: LegacyTapGesture;
tileSize: number;
rowGap: number;
columnGap: number;
Expand Down
30 changes: 16 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,
LegacyPanGesture,
LegacyTapGesture,
} 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<LegacyPanGesture>(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<LegacyPanGesture>(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<LegacyPanGesture>(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<LegacyPanGesture>(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<LegacyPanGesture>(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<LegacyTapGesture>(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<LegacyTapGesture>(getByGestureTestId('tap'), [
{ state: State.FAILED },
]);
expect(handlers.begin).toHaveBeenCalledTimes(1);
Expand All @@ -488,7 +488,9 @@
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<LegacyPanGesture>(getByGestureTestId('pan'), [
{ x: 120 },
]);
expect(handlers.begin).toHaveBeenCalledWith(
expect.objectContaining({ x: 120 })
);
Expand All @@ -501,7 +503,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<LegacyPanGesture>(getByGestureTestId('pan'), [
{ x: 120, state: State.FAILED },
]);
expect(handlers.begin).toHaveBeenCalledTimes(1);
Expand All @@ -515,7 +517,7 @@
test('uses event data filled events', () => {
const handlers = mockedEventHandlers();
render(<RacingTapAndPan handlers={handlers} treatStartAsUpdate />);
fireGestureHandler<PanGesture>(getByGestureTestId('pan'), [
fireGestureHandler<LegacyPanGesture>(getByGestureTestId('pan'), [
{ x: 5, y: 15 },
{ x: 6, y: 16 },
{ x: 7, y: 17 },
Expand All @@ -533,15 +535,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<LegacyTapGesture>(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<LegacyPanGesture>(getByGestureTestId('pan'));
expect(handlers.begin).toHaveBeenCalledTimes(1);
expect(handlers.active).toHaveBeenCalledTimes(1);
expect(handlers.end).toHaveBeenCalledTimes(1);
Expand Down
29 changes: 15 additions & 14 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 as LegacyTapGesture } from './handlers/gestures/tapGesture';
export type { PanGestureType as LegacyPanGesture } from './handlers/gestures/panGesture';
export type { FlingGestureType as LegacyFlingGesture } from './handlers/gestures/flingGesture';
export type { LongPressGestureType as LegacyLongPressGesture } from './handlers/gestures/longPressGesture';
export type { PinchGestureType as LegacyPinchGesture } from './handlers/gestures/pinchGesture';
export type { RotationGestureType as LegacyRotationGesture } from './handlers/gestures/rotationGesture';
export type { ForceTouchGestureType as LegacyForceTouchGesture } from './handlers/gestures/forceTouchGesture';
export type { ManualGestureType as LegacyManualGesture } from './handlers/gestures/manualGesture';
export type { HoverGestureType as LegacyHoverGesture } from './handlers/gestures/hoverGesture';
export type {
ComposedGestureType as ComposedGesture,
RaceGestureType as RaceGesture,
SimultaneousGestureType as SimultaneousGesture,
ExclusiveGestureType as ExclusiveGesture,
ComposedGestureType as LegacyComposedGesture,
RaceGestureType as LegacyRaceGesture,
SimultaneousGestureType as LegacySimultaneousGesture,
ExclusiveGestureType as LegacyExclusiveGesture,
} from './handlers/gestures/gestureComposition';
export type { GestureStateManagerType as GestureStateManager } from './handlers/gestures/gestureStateManager';
export { NativeViewGestureHandler } from './handlers/NativeViewGestureHandler';
Expand Down Expand Up @@ -157,7 +157,8 @@ export { LogicDetector } from './v3/LogicDetector';
export * from './v3/hooks/useGesture';
export * from './v3/hooks/relations';

export { SingleGestureName } from './v3/types';
export type { ComposedGesture } from './v3/types';
export type { GestureTouchEvent as SingleGestureTouchEvent } from './handlers/gestureHandlerCommon';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this reexport to keep naming consistency, but I'm not sure whether this is the best approach. Let me know what you think


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

Expand Down
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 @@ -32,3 +35,12 @@ export function useFling(config: FlingGestureConfig) {

return useGesture(SingleGestureName.Fling, flingConfig);
}

export type FlingGestureStateChangeEvent =
GestureStateChangeEvent<FlingHandlerData>;
export type FlingGestureUpdateEvent = GestureUpdateEvent<FlingHandlerData>;
Comment on lines +39 to +41
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we could move it (along with FlingHandlerData to FlingProperties file (and probably rename it so it would make sense).

But this one is also fine, if we decide to change it we can do it later 😅


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 @@ -54,3 +57,12 @@ export function useHover(config: HoverGestureConfig) {

return useGesture(SingleGestureName.Hover, hoverConfig);
}

export type HoverGestureStateChangeEvent =
GestureStateChangeEvent<HoverHandlerData>;
export type HoverGestureUpdateEvent = GestureUpdateEvent<HoverHandlerData>;

export type HoverGesture = SingleGesture<
HoverHandlerData,
HoverGestureProperties
>;
114 changes: 114 additions & 0 deletions packages/react-native-gesture-handler/src/v3/hooks/gestures/index.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,140 @@
import type {
FlingGestureStateChangeEvent,
FlingGestureUpdateEvent,
FlingGesture,
} from './fling/useFling';
import type {
HoverGestureStateChangeEvent,
HoverGestureUpdateEvent,
HoverGesture,
} from './hover/useHover';
import type {
LongPressGestureStateChangeEvent,
LongPressGestureUpdateEvent,
LongPressGesture,
} from './longPress/useLongPress';
import type {
ManualGestureStateChangeEvent,
ManualGestureUpdateEvent,
ManualGesture,
} from './manual/useManual';
import type {
NativeGestureStateChangeEvent,
NativeGestureUpdateEvent,
NativeGesture,
} from './native/useNative';
import type {
PanGestureStateChangeEvent,
PanGestureUpdateEvent,
PanGesture,
} from './pan/usePan';
import type {
PinchGestureStateChangeEvent,
PinchGestureUpdateEvent,
PinchGesture,
} from './pinch/usePinch';
import type {
RotationGestureStateChangeEvent,
RotationGestureUpdateEvent,
RotationGesture,
} from './rotation/useRotation';
import type {
TapGestureStateChangeEvent,
TapGestureUpdateEvent,
TapGesture,
} from './tap/useTap';

export type { TapGestureConfig } from './tap/useTap';
export type { TapGesture, TapGestureStateChangeEvent, TapGestureUpdateEvent };
export { useTap } from './tap/useTap';

export type { FlingGestureConfig } from './fling/useFling';
export type {
FlingGesture,
FlingGestureStateChangeEvent,
FlingGestureUpdateEvent,
};
export { useFling } from './fling/useFling';

export type { LongPressGestureConfig } from './longPress/useLongPress';
export type {
LongPressGesture,
LongPressGestureStateChangeEvent,
LongPressGestureUpdateEvent,
};
export { useLongPress } from './longPress/useLongPress';

export type { PinchGestureConfig } from './pinch/usePinch';
export type {
PinchGesture,
PinchGestureStateChangeEvent,
PinchGestureUpdateEvent,
};
export { usePinch } from './pinch/usePinch';

export type { RotationGestureConfig } from './rotation/useRotation';
export type {
RotationGesture,
RotationGestureStateChangeEvent,
RotationGestureUpdateEvent,
};
export { useRotation } from './rotation/useRotation';

export type { HoverGestureConfig } from './hover/useHover';
export type {
HoverGesture,
HoverGestureStateChangeEvent,
HoverGestureUpdateEvent,
};
export { useHover } from './hover/useHover';

export type { ManualGestureConfig } from './manual/useManual';
export type {
ManualGesture,
ManualGestureStateChangeEvent,
ManualGestureUpdateEvent,
};
export { useManual } from './manual/useManual';

export type { NativeViewGestureConfig } from './native/useNative';
export type {
NativeGesture,
NativeGestureStateChangeEvent,
NativeGestureUpdateEvent,
};
export { useNative } from './native/useNative';

export type { PanGestureConfig } from './pan/usePan';
export type { PanGesture, PanGestureStateChangeEvent, PanGestureUpdateEvent };
export { usePan } from './pan/usePan';

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

export type SingleGestureStateChangeEvent =
| TapGestureStateChangeEvent
| FlingGestureStateChangeEvent
| LongPressGestureStateChangeEvent
| RotationGestureStateChangeEvent
| HoverGestureStateChangeEvent
| ManualGestureStateChangeEvent
| NativeGestureStateChangeEvent
| PanGestureStateChangeEvent;

export type SingleGestureUpdateEvent =
| TapGestureUpdateEvent
| FlingGestureUpdateEvent
| LongPressGestureUpdateEvent
| RotationGestureUpdateEvent
| HoverGestureUpdateEvent
| ManualGestureUpdateEvent
| NativeGestureUpdateEvent
| PanGestureUpdateEvent;
Loading
Loading