Skip to content

Commit

Permalink
add first to eventData (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
hartzis authored Nov 29, 2019
1 parent 7b00a48 commit 962a5a0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions src/__tests__/__snapshots__/index.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Array [
"deltaY": 0,
"dir": "Right",
"event": Object {},
"first": false,
"initial": Array [
100,
100,
Expand All @@ -35,6 +36,7 @@ Array [
"preventDefault": [MockFunction],
"timeStamp": 1374825.199999963,
},
"first": true,
"initial": Array [
100,
100,
Expand All @@ -55,6 +57,7 @@ Array [
"preventDefault": [MockFunction],
"timeStamp": 1374841.3999999757,
},
"first": false,
"initial": Array [
100,
100,
Expand All @@ -75,6 +78,7 @@ Array [
"preventDefault": [MockFunction],
"timeStamp": 1374857.399999979,
},
"first": false,
"initial": Array [
100,
100,
Expand All @@ -95,6 +99,7 @@ Array [
"preventDefault": [MockFunction],
"timeStamp": 1374873.499999987,
},
"first": false,
"initial": Array [
100,
100,
Expand Down Expand Up @@ -123,6 +128,7 @@ Array [
},
],
},
"first": false,
"initial": Array [
100,
100,
Expand Down Expand Up @@ -152,6 +158,7 @@ Array [
},
],
},
"first": true,
"initial": Array [
100,
100,
Expand All @@ -176,6 +183,7 @@ Array [
},
],
},
"first": false,
"initial": Array [
100,
100,
Expand All @@ -200,6 +208,7 @@ Array [
},
],
},
"first": false,
"initial": Array [
100,
100,
Expand All @@ -224,6 +233,7 @@ Array [
},
],
},
"first": false,
"initial": Array [
100,
100,
Expand All @@ -244,6 +254,7 @@ Array [
"deltaY": 0,
"dir": "Right",
"event": Object {},
"first": false,
"initial": Array [
100,
100,
Expand All @@ -269,6 +280,7 @@ Array [
"preventDefault": [MockFunction],
"timeStamp": 1374825.199999963,
},
"first": true,
"initial": Array [
100,
100,
Expand All @@ -289,6 +301,7 @@ Array [
"preventDefault": [MockFunction],
"timeStamp": 1374841.3999999757,
},
"first": false,
"initial": Array [
100,
100,
Expand All @@ -309,6 +322,7 @@ Array [
"preventDefault": [MockFunction],
"timeStamp": 1374857.399999979,
},
"first": false,
"initial": Array [
100,
100,
Expand All @@ -329,6 +343,7 @@ Array [
"preventDefault": [MockFunction],
"timeStamp": 1374873.499999987,
},
"first": false,
"initial": Array [
100,
100,
Expand Down Expand Up @@ -357,6 +372,7 @@ Array [
},
],
},
"first": false,
"initial": Array [
100,
100,
Expand Down Expand Up @@ -386,6 +402,7 @@ Array [
},
],
},
"first": true,
"initial": Array [
100,
100,
Expand All @@ -410,6 +427,7 @@ Array [
},
],
},
"first": false,
"initial": Array [
100,
100,
Expand All @@ -434,6 +452,7 @@ Array [
},
],
},
"first": false,
"initial": Array [
100,
100,
Expand All @@ -458,6 +477,7 @@ Array [
},
],
},
"first": false,
"initial": Array [
100,
100,
Expand Down
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function getHandlers(set, handlerProps) {
return {
...state,
...initialState,
eventData: { initial: [...xy] },
eventData: { initial: [...xy], first: true },
xy,
start: event.timeStamp || 0
}
Expand Down Expand Up @@ -105,7 +105,8 @@ function getHandlers(set, handlerProps) {
)
event.preventDefault()

return { ...state, eventData, swiping: true }
// first is now always false
return { ...state, eventData: { ...eventData, first: false }, swiping: true }
})
}

Expand Down
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface EventData {
deltaY: number
absX: number
absY: number
first: boolean
initial: Vector2
velocity: number
dir: 'Left' | 'Right' | 'Up' | 'Down'
Expand Down
12 changes: 1 addition & 11 deletions types/test.tsx
Original file line number Diff line number Diff line change
@@ -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<SwipeableProps> {
private readonly handleSwiped: SwipeCallback = () => {}
private readonly handleSwipedLeft: SwipeCallback = () => {}
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 962a5a0

Please sign in to comment.