diff --git a/dist/index.js b/dist/index.js index afb7eaa..7b6661c 100755 --- a/dist/index.js +++ b/dist/index.js @@ -71,6 +71,9 @@ var LongPressable = function (_React$PureComponent) { } } + // re-initialize long press + _this.isLongPressing = false; + _this.startingPosition = eventToPosition(e); _this.timerID = setTimeout(function () { diff --git a/src/index.js b/src/index.js index 486dfa1..1132aa2 100755 --- a/src/index.js +++ b/src/index.js @@ -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(() => { diff --git a/test/index.test.js b/test/index.test.js index 9a740fc..ee3124a 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -110,4 +110,20 @@ describe('', () => { 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) + } ) + } )