react-native-gesture-handler
Version:
Declarative API exposing native platform touch and gesture system to React Native
61 lines (53 loc) • 1.79 kB
text/typescript
import type { GestureUpdateEvent } from '../gestureHandlerCommon';
import type { PinchGestureHandlerEventPayload } from '../GestureHandlerEventPayload';
import { ContinousBaseGesture } from './gesture';
/**
* @deprecated `PinchGestureChangeEventPayload` is deprecated and will be removed in the future. Please use `PinchGestureActiveEvent` instead.
*/
export type PinchGestureChangeEventPayload = {
scaleChange: number;
};
function changeEventCalculator(
current: GestureUpdateEvent<PinchGestureHandlerEventPayload>,
previous?: GestureUpdateEvent<PinchGestureHandlerEventPayload>
) {
'worklet';
let changePayload: PinchGestureChangeEventPayload;
if (previous === undefined) {
changePayload = {
scaleChange: current.scale,
};
} else {
changePayload = {
scaleChange: current.scale / previous.scale,
};
}
return { ...current, ...changePayload };
}
/**
* @deprecated `PinchGesture` is deprecated and will be removed in the future. Please use `usePinchGesture` instead.
*/
export class PinchGesture extends ContinousBaseGesture<
PinchGestureHandlerEventPayload,
PinchGestureChangeEventPayload
> {
constructor() {
super();
this.handlerName = 'PinchGestureHandler';
}
override onChange(
callback: (
event: GestureUpdateEvent<
PinchGestureHandlerEventPayload & PinchGestureChangeEventPayload
>
) => void
) {
// @ts-ignore TS being overprotective, PinchGestureHandlerEventPayload is Record
this.handlers.changeEventCalculator = changeEventCalculator;
return super.onChange(callback);
}
}
/**
* @deprecated `PinchGestureType` is deprecated and will be removed in the future. Please use `PinchGesture` instead.
*/
export type PinchGestureType = InstanceType<typeof PinchGesture>;