Skip to content

Commit

Permalink
Unmount PTR if no moves were done; fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pateketrueke committed Sep 10, 2019
1 parent ea555e9 commit 194c21c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/lib/events.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import _ptr from './api';
import _shared from './shared';

let _timeout;

const screenY = function screenY(event) {
if (_shared.pointerEventsEnabled && _shared.supportsPointerEvents) {
return event.screenY;
Expand Down Expand Up @@ -92,6 +94,14 @@ export default () => {
return;
}

// wait 1/2 sec before unmounting...
clearTimeout(_timeout);
_timeout = setTimeout(() => {
if (_shared.state === 'pending') {
_ptr.onReset(_el);
}
}, 500);

if (_shared.state === 'releasing' && _shared.distResisted > _el.distThreshold) {
_shared.state = 'refreshing';

Expand Down
7 changes: 7 additions & 0 deletions tests/e2e/cases/basic.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { pullToRefresh, hasMinHeight, isUnmounted } from '../helpers';
import { t } from 'testcafe';

/* global fixture, test */

Expand All @@ -10,3 +11,9 @@ test('use `mainElement` for prepending before a given element', async () => {
await pullToRefresh('body', 100, 200);
await hasMinHeight();
});

test('should remove PTR-element if no move intentions are made', async () => {
await isUnmounted();
await t.click('body').wait(500);
await isUnmounted();
});

0 comments on commit 194c21c

Please sign in to comment.