Skip to content
Draft
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,4 +1,5 @@
import { isTestEnv } from '../utils';
import type { AnySingleGesture } from '../v3/hooks/gestures/singleGestureUnion';
import type { SingleGesture } from '../v3/types';
import type {
GestureEvent,
Expand All @@ -8,10 +9,9 @@ import type { GestureType } from './gestures/gesture';

export const handlerIDToTag: Record<string, number> = {};

// There were attempts to create types that merge possible HandlerData and Config,
// but ts was not able to infer them properly in many cases, so we use any here.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const hookGestures = new Map<number, SingleGesture<any, any, any>>();
// Stored as the discriminated union of concrete v3 gestures so lookups by
// test ID can narrow on the `type` field.
const hookGestures = new Map<number, AnySingleGesture>();
const gestures = new Map<number, GestureType>();
const oldHandlers = new Map<number, GestureHandlerCallbacks>();
const testIDs = new Map<string, number>();
Expand All @@ -25,7 +25,9 @@ export function registerGesture<
gesture: SingleGesture<TConfig, THandlerData, TExtendedHandlerData>
) {
if (isTestEnv() && gesture.config.testID) {
hookGestures.set(handlerTag, gesture);
// The generic parameters cannot be correlated with the union members
// here, but every gesture created by the v3 hooks is a union member.
hookGestures.set(handlerTag, gesture as unknown as AnySingleGesture);
testIDs.set(gesture.config.testID, handlerTag);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
ExcludeInternalConfigProps,
GestureEvent,
SingleGesture,
SingleGestureName,
WithSharedValue,
} from '../../../types';

Expand Down Expand Up @@ -56,5 +57,7 @@ export type FlingGestureActiveEvent = FlingGestureEvent;

export type FlingGesture = SingleGesture<
FlingGestureProperties,
FlingHandlerData
FlingHandlerData,
FlingHandlerData,
SingleGestureName.Fling
>;
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
ExcludeInternalConfigProps,
GestureEvent,
SingleGesture,
SingleGestureName,
WithSharedValue,
} from '../../../types';

Expand Down Expand Up @@ -72,5 +73,6 @@ export type HoverGestureActiveEvent = GestureEvent<HoverExtendedHandlerData>;
export type HoverGesture = SingleGesture<
HoverGestureInternalProperties,
HoverHandlerData,
HoverExtendedHandlerData
HoverExtendedHandlerData,
SingleGestureName.Hover
>;
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,8 @@ export type {
PanGestureEvent,
};
export { usePanGesture } from './pan/usePanGesture';

export type SingleGesture =
| TapGesture
| FlingGesture
| LongPressGesture
| PinchGesture
| RotationGesture
| HoverGesture
| ManualGesture
| NativeGesture
| PanGesture;
export type { AnySingleGesture } from './singleGestureUnion';
export type { AnySingleGesture as SingleGesture } from './singleGestureUnion';

/* eslint-disable @typescript-eslint/no-duplicate-type-constituents */
export type SingleGestureEvent =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
ExcludeInternalConfigProps,
GestureEvent,
SingleGesture,
SingleGestureName,
WithSharedValue,
} from '../../../types';

Expand Down Expand Up @@ -68,5 +69,7 @@ export type LongPressGestureActiveEvent = LongPressGestureEvent;

export type LongPressGesture = SingleGesture<
LongPressGestureProperties,
LongPressHandlerData
LongPressHandlerData,
LongPressHandlerData,
SingleGestureName.LongPress
>;
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ export function useLongPressGesture(
LongPressGestureInternalProperties
>(config, LongPressPropsMapping, transformLongPressProps);

return useGesture<LongPressGestureInternalProperties, LongPressHandlerData>(
SingleGestureName.LongPress,
longPressConfig
);
return useGesture<
LongPressGestureInternalProperties,
LongPressHandlerData,
LongPressHandlerData,
SingleGestureName.LongPress
>(SingleGestureName.LongPress, longPressConfig);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
ExcludeInternalConfigProps,
GestureEvent,
SingleGesture,
SingleGestureName,
} from '../../../types';

export type ManualGestureNativeProperties = Record<string, never>;
Expand All @@ -24,5 +25,7 @@ export type ManualGestureActiveEvent = ManualGestureEvent;

export type ManualGesture = SingleGesture<
ManualGestureProperties,
ManualHandlerData
ManualHandlerData,
ManualHandlerData,
SingleGestureName.Manual
>;
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
ExcludeInternalConfigProps,
GestureEvent,
SingleGesture,
SingleGestureName,
WithSharedValue,
} from '../../../types';

Expand Down Expand Up @@ -58,5 +59,7 @@ export type NativeGestureActiveEvent = NativeGestureEvent;

export type NativeGesture = SingleGesture<
NativeGestureProperties,
NativeHandlerData
NativeHandlerData,
NativeHandlerData,
SingleGestureName.Native
>;
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
ExcludeInternalConfigProps,
GestureEvent,
SingleGesture,
SingleGestureName,
WithSharedValue,
} from '../../../types';

Expand Down Expand Up @@ -170,5 +171,6 @@ export type PanGestureActiveEvent = GestureEvent<PanExtendedHandlerData>;
export type PanGesture = SingleGesture<
PanGestureInternalProperties,
PanHandlerData,
PanExtendedHandlerData
PanExtendedHandlerData,
SingleGestureName.Pan
>;
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export function usePanGesture(
return useGesture<
PanGestureInternalProperties,
PanHandlerData,
PanExtendedHandlerData
PanExtendedHandlerData,
SingleGestureName.Pan
>(SingleGestureName.Pan, panConfig);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
ExcludeInternalConfigProps,
GestureEvent,
SingleGesture,
SingleGestureName,
} from '../../../types';

export type PinchGestureNativeProperties = Record<string, never>;
Expand Down Expand Up @@ -36,5 +37,6 @@ export type PinchGestureActiveEvent = GestureEvent<PinchExtendedHandlerData>;
export type PinchGesture = SingleGesture<
PinchGestureProperties,
PinchHandlerData,
PinchExtendedHandlerData
PinchExtendedHandlerData,
SingleGestureName.Pinch
>;
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
ExcludeInternalConfigProps,
GestureEvent,
SingleGesture,
SingleGestureName,
} from '../../../types';

export type RotationGestureNativeProperties = Record<string, never>;
Expand Down Expand Up @@ -37,5 +38,6 @@ export type RotationGestureActiveEvent =
export type RotationGesture = SingleGesture<
RotationGestureProperties,
RotationHandlerData,
RotationExtendedHandlerData
RotationExtendedHandlerData,
SingleGestureName.Rotation
>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { FlingGesture } from './fling/FlingTypes';
import type { HoverGesture } from './hover/HoverTypes';
import type { LongPressGesture } from './longPress/LongPressTypes';
import type { ManualGesture } from './manual/ManualTypes';
import type { NativeGesture } from './native/NativeTypes';
import type { PanGesture } from './pan/PanTypes';
import type { PinchGesture } from './pinch/PinchTypes';
import type { RotationGesture } from './rotation/RotationTypes';
import type { TapGesture } from './tap/TapTypes';

export type AnySingleGesture =
| TapGesture
| FlingGesture
| LongPressGesture
| PinchGesture
| RotationGesture
| HoverGesture
| ManualGesture
| NativeGesture
| PanGesture;
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
DiscreteSingleGesture,
ExcludeInternalConfigProps,
GestureEvent,
SingleGestureName,
WithSharedValue,
} from '../../../types';

Expand Down Expand Up @@ -96,5 +97,7 @@ export type TapGestureActiveEvent = TapGestureEvent;

export type TapGesture = DiscreteSingleGesture<
TapGestureInternalProperties,
TapHandlerData
TapHandlerData,
TapHandlerData,
SingleGestureName.Tap
>;
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ export function useTapGesture(
TapGestureInternalProperties
>(config, TapPropsMapping);

return useGesture<TapGestureInternalProperties, TapHandlerData>(
SingleGestureName.Tap,
tapConfig
);
return useGesture<
TapGestureInternalProperties,
TapHandlerData,
TapHandlerData,
SingleGestureName.Tap
>(SingleGestureName.Tap, tapConfig);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ export function useGesture<
TConfig,
THandlerData,
TExtendedHandlerData extends THandlerData = THandlerData,
TType extends SingleGestureName = SingleGestureName,
>(
type: SingleGestureName,
type: TType,
config: BaseGestureConfig<TConfig, THandlerData, TExtendedHandlerData>
): SingleGesture<TConfig, THandlerData, TExtendedHandlerData> {
): SingleGesture<TConfig, THandlerData, TExtendedHandlerData, TType> {
const handlerTag = useMemo(() => getNextHandlerTag(), []);
const disableReanimated = useMemo(() => config.disableReanimated, []);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ export type SingleGesture<
TConfig,
THandlerData,
TExtendedHandlerData extends THandlerData = THandlerData,
TType extends SingleGestureName = SingleGestureName,
> = {
handlerTag: number;
type: SingleGestureName;
type: TType;
config: BaseGestureConfig<TConfig, THandlerData, TExtendedHandlerData>;
detectorCallbacks: DetectorCallbacks<THandlerData, TExtendedHandlerData>;
gestureRelations: GestureRelations;
Expand All @@ -51,17 +52,19 @@ export type DiscreteSingleGesture<
TConfig,
THandlerData,
TExtendedHandlerData extends THandlerData = THandlerData,
TType extends SingleGestureName = SingleGestureName,
> = {
[K in keyof SingleGesture<
TConfig,
THandlerData,
TExtendedHandlerData
TExtendedHandlerData,
TType
>]: K extends 'config'
? Omit<
SingleGesture<TConfig, THandlerData, TExtendedHandlerData>[K],
SingleGesture<TConfig, THandlerData, TExtendedHandlerData, TType>[K],
'onUpdate'
>
: SingleGesture<TConfig, THandlerData, TExtendedHandlerData>[K];
: SingleGesture<TConfig, THandlerData, TExtendedHandlerData, TType>[K];
};

export type ComposedGesture = {
Expand Down
Loading