From 99cc0a5980397c93049197927826179a3e074070 Mon Sep 17 00:00:00 2001 From: Brian Emil Hartz Date: Thu, 15 Aug 2019 22:15:35 -0600 Subject: [PATCH 1/4] add first to eventData --- src/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index f7d79d6e..0e58b112 100644 --- a/src/index.js +++ b/src/index.js @@ -61,7 +61,7 @@ function getHandlers(set, handlerProps) { return { ...state, ...initialState, - eventData: { initial: [...xy] }, + eventData: { initial: [...xy], first: true }, xy, start: event.timeStamp || 0 } @@ -86,7 +86,7 @@ function getHandlers(set, handlerProps) { if (absX < props.delta && absY < props.delta && !state.swiping) return state const dir = getDirection(absX, absY, deltaX, deltaY) - const eventData = { ...state.eventData, event, absX, absY, deltaX, deltaY, velocity, dir } + let eventData = { ...state.eventData, event, absX, absY, deltaX, deltaY, velocity, dir } props.onSwiping && props.onSwiping(eventData) @@ -105,6 +105,7 @@ function getHandlers(set, handlerProps) { ) event.preventDefault() + eventData.first = false; return { ...state, eventData, swiping: true } }) } From a726c83a0734b81dcb4637d80bd541f39d05e4bc Mon Sep 17 00:00:00 2001 From: Brian Emil Hartz Date: Sun, 25 Aug 2019 11:28:57 -0600 Subject: [PATCH 2/4] add first to readme eventdata --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index cf40b0e2..66c20e4f 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ All Event Handlers are called with the below event data. { event, // source event initial, // initial swipe [x,y] + first, // true for first event deltaX, // x offset (initial.x - current.x) deltaY, // y offset (initial.y - current.y) absX, // absolute deltaX From 0aaf163e350182a15d523f7bf8aea43c9a07b640 Mon Sep 17 00:00:00 2001 From: Brian Emil Hartz Date: Thu, 28 Nov 2019 20:47:56 -0700 Subject: [PATCH 3/4] update tests and types --- .../__snapshots__/index.spec.js.snap | 20 +++++++++++++++++++ src/index.js | 4 ++-- types/index.d.ts | 1 + types/test.tsx | 12 +---------- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/__tests__/__snapshots__/index.spec.js.snap b/src/__tests__/__snapshots__/index.spec.js.snap index dfb28378..397592ef 100644 --- a/src/__tests__/__snapshots__/index.spec.js.snap +++ b/src/__tests__/__snapshots__/index.spec.js.snap @@ -10,6 +10,7 @@ Array [ "deltaY": 0, "dir": "Right", "event": Object {}, + "first": false, "initial": Array [ 100, 100, @@ -35,6 +36,7 @@ Array [ "preventDefault": [MockFunction], "timeStamp": 1374825.199999963, }, + "first": true, "initial": Array [ 100, 100, @@ -55,6 +57,7 @@ Array [ "preventDefault": [MockFunction], "timeStamp": 1374841.3999999757, }, + "first": false, "initial": Array [ 100, 100, @@ -75,6 +78,7 @@ Array [ "preventDefault": [MockFunction], "timeStamp": 1374857.399999979, }, + "first": false, "initial": Array [ 100, 100, @@ -95,6 +99,7 @@ Array [ "preventDefault": [MockFunction], "timeStamp": 1374873.499999987, }, + "first": false, "initial": Array [ 100, 100, @@ -123,6 +128,7 @@ Array [ }, ], }, + "first": false, "initial": Array [ 100, 100, @@ -152,6 +158,7 @@ Array [ }, ], }, + "first": true, "initial": Array [ 100, 100, @@ -176,6 +183,7 @@ Array [ }, ], }, + "first": false, "initial": Array [ 100, 100, @@ -200,6 +208,7 @@ Array [ }, ], }, + "first": false, "initial": Array [ 100, 100, @@ -224,6 +233,7 @@ Array [ }, ], }, + "first": false, "initial": Array [ 100, 100, @@ -244,6 +254,7 @@ Array [ "deltaY": 0, "dir": "Right", "event": Object {}, + "first": false, "initial": Array [ 100, 100, @@ -269,6 +280,7 @@ Array [ "preventDefault": [MockFunction], "timeStamp": 1374825.199999963, }, + "first": true, "initial": Array [ 100, 100, @@ -289,6 +301,7 @@ Array [ "preventDefault": [MockFunction], "timeStamp": 1374841.3999999757, }, + "first": false, "initial": Array [ 100, 100, @@ -309,6 +322,7 @@ Array [ "preventDefault": [MockFunction], "timeStamp": 1374857.399999979, }, + "first": false, "initial": Array [ 100, 100, @@ -329,6 +343,7 @@ Array [ "preventDefault": [MockFunction], "timeStamp": 1374873.499999987, }, + "first": false, "initial": Array [ 100, 100, @@ -357,6 +372,7 @@ Array [ }, ], }, + "first": false, "initial": Array [ 100, 100, @@ -386,6 +402,7 @@ Array [ }, ], }, + "first": true, "initial": Array [ 100, 100, @@ -410,6 +427,7 @@ Array [ }, ], }, + "first": false, "initial": Array [ 100, 100, @@ -434,6 +452,7 @@ Array [ }, ], }, + "first": false, "initial": Array [ 100, 100, @@ -458,6 +477,7 @@ Array [ }, ], }, + "first": false, "initial": Array [ 100, 100, diff --git a/src/index.js b/src/index.js index 0e58b112..3db13980 100644 --- a/src/index.js +++ b/src/index.js @@ -105,8 +105,8 @@ function getHandlers(set, handlerProps) { ) event.preventDefault() - eventData.first = false; - return { ...state, eventData, swiping: true } + // first is now always false + return { ...state, eventData: { ...eventData, first: false }, swiping: true } }) } diff --git a/types/index.d.ts b/types/index.d.ts index fd8f677a..aae9b4c5 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -9,6 +9,7 @@ export interface EventData { deltaY: number absX: number absY: number + first: boolean initial: Vector2 velocity: number dir: 'Left' | 'Right' | 'Up' | 'Down' diff --git a/types/test.tsx b/types/test.tsx index 93aac26a..40ce4b21 100644 --- a/types/test.tsx +++ b/types/test.tsx @@ -1,17 +1,6 @@ import * as React from 'react' import { Swipeable, SwipeableHandlers, SwipeableProps, SwipeCallback, useSwipeable } from 'react-swipeable' -interface CopyOfEventData { - event: MouseEvent | TouchEvent - deltaX: number - deltaY: number - absX: number - absY: number - // initial: Vector2 - velocity: number - dir: 'Left' | 'Right' | 'Up' | 'Down' -} - class SampleComponent extends React.PureComponent { private readonly handleSwiped: SwipeCallback = () => {} private readonly handleSwipedLeft: SwipeCallback = () => {} @@ -77,6 +66,7 @@ const handlers: SwipeableHandlers = useSwipeable({ deltaY, // $ExpectType number absX, // $ExpectType number absY, // $ExpectType number + first, // $ExpectType boolean initial, // $ExpectType [number, number] velocity, // $ExpectType number dir, // $ExpectType "Left" | "Right" | "Up" | "Down" From 7454eb76f6d696d560e1325cbb814d8ade71de92 Mon Sep 17 00:00:00 2001 From: Brian Emil Hartz Date: Fri, 29 Nov 2019 13:54:20 -0700 Subject: [PATCH 4/4] back to const --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 3db13980..0ffeb07e 100644 --- a/src/index.js +++ b/src/index.js @@ -86,7 +86,7 @@ function getHandlers(set, handlerProps) { if (absX < props.delta && absY < props.delta && !state.swiping) return state const dir = getDirection(absX, absY, deltaX, deltaY) - let eventData = { ...state.eventData, event, absX, absY, deltaX, deltaY, velocity, dir } + const eventData = { ...state.eventData, event, absX, absY, deltaX, deltaY, velocity, dir } props.onSwiping && props.onSwiping(eventData)