react-native-gesture-handler
Version:
Experimental implementation of a new declarative API for gesture handling in react-native
37 lines (30 loc) • 1.22 kB
text/typescript
import { BaseGesture, BaseGestureConfig } from './gesture';
import { LongPressGestureConfig } from '../LongPressGestureHandler';
import type { LongPressGestureHandlerEventPayload } from '../GestureHandlerEventPayload';
export class LongPressGesture extends BaseGesture<LongPressGestureHandlerEventPayload> {
public config: BaseGestureConfig & LongPressGestureConfig = {};
constructor() {
super();
this.handlerName = 'LongPressGestureHandler';
this.shouldCancelWhenOutside(true);
}
/**
* Minimum time, expressed in milliseconds, that a finger must remain pressed on the corresponding view.
* The default value is 500.
* @param duration
*/
minDuration(duration: number) {
this.config.minDurationMs = duration;
return this;
}
/**
* Maximum distance, expressed in points, that defines how far the finger is allowed to travel during a long press gesture.
* @param distance
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/long-press-gesture#maxdistancevalue-number
*/
maxDistance(distance: number) {
this.config.maxDist = distance;
return this;
}
}
export type LongPressGestureType = InstanceType<typeof LongPressGesture>;