From ba817ae60a3024d9d897ac18cdb8a2c1e2d1c822 Mon Sep 17 00:00:00 2001 From: Emil Hartz Date: Thu, 24 Feb 2022 21:28:21 -0700 Subject: [PATCH 1/2] add comments to types for more info --- README.md | 2 +- src/types.ts | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f4cc8e66..6c763a82 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ All Event Handlers are called with the below event data, `SwipeEventData`. { event, // source event initial, // initial swipe [x,y] - first, // true for first event + first, // True for the first event of a tracked swipe deltaX, // x offset (current.x - initial.x) deltaY, // y offset (current.y - initial.y) absX, // absolute deltaX diff --git a/src/types.ts b/src/types.ts index 4d2342b2..8c04ecd9 100644 --- a/src/types.ts +++ b/src/types.ts @@ -12,30 +12,84 @@ export type SwipeDirections = | typeof UP | typeof DOWN; export interface SwipeEventData { + /** + * Absolute displacement of swipe in x. Math.abs(deltaX); + */ absX: number; + /** + * Absolute displacement of swipe in y. Math.abs(deltaY); + */ absY: number; + /** + * Displacement of swipe in x. (current.x - initial.x) + */ deltaX: number; + /** + * Displacement of swipe in y. (current.y - initial.y) + */ deltaY: number; + /** + * Direction of swipe - Left | Right | Up | Down + */ dir: SwipeDirections; + /** + * Source event. + */ event: HandledEvents; + /** + * True for the first event of a tracked swipe. + */ first: boolean; + /** + * Location where swipe started. + */ initial: Vector2; + /** + * "Absolute velocity" (speed) - √(absX^2 + absY^2) / time + */ velocity: number; + /** + * Velocity per axis - [ deltaX/time, deltaY/time ] + */ vxvy: Vector2; } export type SwipeCallback = (eventData: SwipeEventData) => void; export type TapCallback = ({ event }: { event: HandledEvents }) => void; +// Event handler/callbacks export type SwipeableCallbacks = { - // Event handler/callbacks + /** + * Called at start of a tracked swipe. + */ onSwipeStart: SwipeCallback; + /** + * Called after any swipe. + */ onSwiped: SwipeCallback; + /** + * Called after a DOWN swipe + */ onSwipedDown: SwipeCallback; + /** + * Called after a LEFT swipe + */ onSwipedLeft: SwipeCallback; + /** + * Called after a RIGHT swipe + */ onSwipedRight: SwipeCallback; + /** + * Called after a UP swipe + */ onSwipedUp: SwipeCallback; + /** + * Called for each move event during a tracked swipe. + */ onSwiping: SwipeCallback; + /** + * Called after a tap. A touch under the min distance, `delta`. + */ onTap: TapCallback; }; @@ -43,11 +97,27 @@ export type SwipeableCallbacks = { export type ConfigurationOptionDelta = | number | { [key in Lowercase]?: number }; + export interface ConfigurationOptions { + /** + * Min distance(px) before a swipe starts. **Default**: `10` + */ delta: ConfigurationOptionDelta; + /** + * Prevents scroll during swipe in most cases. **Default**: `false` + */ preventScrollOnSwipe: boolean; + /** + * Set a rotation angle. **Default**: `0` + */ rotationAngle: number; + /** + * Track mouse input. **Default**: `false` + */ trackMouse: boolean; + /** + * Track touch input. **Default**: `true` + */ trackTouch: boolean; } From 4c623802814f37d2b54f8e88d1cf706dbd739fb6 Mon Sep 17 00:00:00 2001 From: "(Brian) Emil Hartz" Date: Fri, 18 Mar 2022 12:04:42 -0600 Subject: [PATCH 2/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6c763a82..b8c58bec 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ All Event Handlers are called with the below event data, `SwipeEventData`. { event, // source event initial, // initial swipe [x,y] - first, // True for the first event of a tracked swipe + first, // true for the first event of a tracked swipe deltaX, // x offset (current.x - initial.x) deltaY, // y offset (current.y - initial.y) absX, // absolute deltaX