import type { GestureTouchEvent } from '../../handlers/gestureHandlerCommon'; import type { PointerType } from '../../PointerType'; import type { State } from '../../State'; // Structural stand-in for a synthetic event carrying `nativeEvent`. Kept // minimal on purpose: RN 0.87's Strict TS API makes the other synthetic-event // fields optional, so any richer shape stops being a superset of the real // `NativeSyntheticEvent` across RN versions. We only ever read `nativeEvent`. export type NativeEventWrapper = { nativeEvent: T; }; // Payload of the managed button's press events. The codegen spec // (`specs/RNGestureHandlerButtonNativeComponent`) declares its own // codegen type — specs must stay self-contained for the codegen parser export type ButtonEvent = Readonly<{ pointerInside: boolean; x: number; y: number; absoluteX: number; absoluteY: number; numberOfPointers: number; pointerType: PointerType; }>; type EventPayload = { handlerTag: number; state: State; }; type StateChangeEventPayload = EventPayload & { oldState: State; }; type BaseHandlerData = { numberOfPointers: number; pointerType: PointerType; }; export type HandlerData = BaseHandlerData & T; export type GestureUpdateEventWithHandlerData = EventPayload & { handlerData: HandlerData; }; export type GestureStateChangeEventWithHandlerData = StateChangeEventPayload & { handlerData: HandlerData; }; export type GestureHandlerEventWithHandlerData< THandlerData, TExtendedHandlerData extends THandlerData = THandlerData, > = | UpdateEventWithHandlerData | StateChangeEventWithHandlerData | TouchEvent; export type UnpackedGestureHandlerEventWithHandlerData< THandlerData, TExtendedHandlerData extends THandlerData = THandlerData, > = | GestureUpdateEventWithHandlerData | GestureStateChangeEventWithHandlerData | GestureTouchEvent; export type UpdateEventWithHandlerData = | GestureUpdateEventWithHandlerData | NativeEventWrapper>; export type StateChangeEventWithHandlerData = | GestureStateChangeEventWithHandlerData | NativeEventWrapper>; export type TouchEvent = | GestureTouchEvent | NativeEventWrapper; export type GestureEvent = { handlerTag: number; } & HandlerData; export type GestureEndEvent = { canceled: boolean; } & GestureEvent; export type UnpackedGestureHandlerEvent = | GestureEvent | GestureTouchEvent; // Structural stand-in for RN's `Animated.Value` as a mapping leaf: the // mapping checks only walk the object structure and never call into the // value, so any non-mapping shape with Animated.Value's core method works. type AnimatedValue = { setValue: (value: number) => void; }; // This is not how Animated.event is typed in React Native. We add _argMapping in order to // have access to the _argMapping property to check for usage of `change*` callbacks. // It's also not typed as a function, which is breaking Gesture Handler type definitions. type AnimatedMapping = { [key: string]: AnimatedMapping } | AnimatedValue; export type AnimatedEvent = { _argMapping: (AnimatedMapping | null)[]; }; export type ChangeCalculatorType = ( current: GestureUpdateEventWithHandlerData, previous?: GestureUpdateEventWithHandlerData ) => GestureUpdateEventWithHandlerData; export type DiffCalculatorType = ( current: HandlerData, previous: HandlerData | null ) => Partial>;