Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ var LongPressable = function (_React$PureComponent) {
}
}

// re-initialize long press
_this.isLongPressing = false;

_this.startingPosition = eventToPosition(e);

_this.timerID = setTimeout(function () {
Expand Down
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ export default class LongPressable extends React.PureComponent {
}
}

// re-initialize long press
this.isLongPressing = false;

this.startingPosition = eventToPosition(e)

this.timerID = setTimeout(() => {
Expand Down
16 changes: 16 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,20 @@ describe('<LongPressable />', () => {
expect(onLongPress).toHaveBeenCalledTimes(0)
} )

it('fires onShortPress when onLongPress previously invoked without onPointerUp invokation', async() => {
const { onLongPress, onShortPress, longPressTime } = getDefaultProps()
const defaultEvent = {
clientX: 0,
clientY: 0
}

const wrapper = renderLongPressable(onShortPress, onLongPress, longPressTime)
wrapper.instance().onPointerDown(defaultEvent)
await timeout(longPressTime + 1)
wrapper.instance().onPointerDown(defaultEvent)
wrapper.instance().onPointerUp(defaultEvent)
expect(onShortPress).toHaveBeenCalledTimes(1)
expect(onLongPress).toHaveBeenCalledTimes(1)
} )

} )