this.resetState()} onMouseDown={()=>this.resetState()}>
@@ -245,6 +254,17 @@ export default class Main extends Component
{
onChange={(e)=>this.updateValue('rotationAngle', getVal(e))} value={rotationAngle}/>
+
+ |
+ swipeDuration:
+ (ms | Infinity)
+ |
+
+ this.updateValue('swipeDuration', getVal(e))} value={swipeDurationTextValue}/>
+ |
+
props.swipeDuration) {
+ return state.swiping ? { ...state, swiping: false } : state;
+ }
+
const { clientX, clientY } =
"touches" in event ? event.touches[0] : event;
const [x, y] = rotateXYByAngle([clientX, clientY], props.rotationAngle);
@@ -203,14 +209,17 @@ function getHandlers(
set((state, props) => {
let eventData: SwipeEventData | undefined;
if (state.swiping && state.eventData) {
- eventData = { ...state.eventData, event };
- props.onSwiped && props.onSwiped(eventData);
-
- const onSwipedDir =
- props[
- `onSwiped${eventData.dir}` as keyof SwipeableDirectionCallbacks
- ];
- onSwipedDir && onSwipedDir(eventData);
+ // if swipe is less than duration fire swiped callbacks
+ if (event.timeStamp - state.start < props.swipeDuration) {
+ eventData = { ...state.eventData, event };
+ props.onSwiped && props.onSwiped(eventData);
+
+ const onSwipedDir =
+ props[
+ `onSwiped${eventData.dir}` as keyof SwipeableDirectionCallbacks
+ ];
+ onSwipedDir && onSwipedDir(eventData);
+ }
} else {
props.onTap && props.onTap({ event });
}
@@ -374,17 +383,14 @@ export function useSwipeable(options: SwipeableProps): SwipeableHandlers {
transientProps.current = {
...defaultProps,
...options,
- // Force defaults for config properties
- delta: options.delta === void 0 ? defaultProps.delta : options.delta,
- rotationAngle:
- options.rotationAngle === void 0
- ? defaultProps.rotationAngle
- : options.rotationAngle,
- trackTouch:
- options.trackTouch === void 0
- ? defaultProps.trackTouch
- : options.trackTouch,
};
+ // Force defaults for config properties
+ let defaultKey: keyof ConfigurationOptions;
+ for (defaultKey in defaultProps) {
+ if (transientProps.current[defaultKey] === void 0) {
+ (transientProps.current[defaultKey] as any) = defaultProps[defaultKey];
+ }
+ }
const [handlers, attachTouch] = React.useMemo(
() =>
diff --git a/src/types.ts b/src/types.ts
index 701e7af1..1978dca9 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -59,8 +59,8 @@ export type TapCallback = ({ event }: { event: HandledEvents }) => void;
export type SwipeableDirectionCallbacks = {
/**
- * Called after a DOWN swipe
- */
+ * Called after a DOWN swipe
+ */
onSwipedDown: SwipeCallback;
/**
* Called after a LEFT swipe
@@ -82,8 +82,8 @@ export type SwipeableCallbacks = SwipeableDirectionCallbacks & {
*/
onSwipeStart: SwipeCallback;
/**
- * Called after any swipe.
- */
+ * Called after any swipe.
+ */
onSwiped: SwipeCallback;
/**
* Called for each move event during a tracked swipe.
@@ -129,6 +129,10 @@ export interface ConfigurationOptions {
* Track touch input. **Default**: `true`
*/
trackTouch: boolean;
+ /**
+ * Allowable duration of a swipe (ms). **Default**: `Infinity`
+ */
+ swipeDuration: number;
/**
* Options for touch event listeners
*/