Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug (with fix): Bubbling (or fast) touch event can cause a single tap to always trigger a taphold due to hold_timer overwrite #156

Closed
dustinbolton opened this issue Dec 1, 2019 · 1 comment
Assignees
Labels
bug The issue outlines a clear bug in the existing code which needs to be fixed now, or next release.

Comments

@dustinbolton
Copy link

dustinbolton commented Dec 1, 2019

If more than one touch event is triggered within the threshold time before the end event triggers (eg. due to propagation) then the first timer(s) detecting how long a touch is being held is overwritten by the new timer (currently stored in the settings.hold_timer variable). This results in the first touch always being detected as a taphold. In my case I have a nested item so a single touch resulted in the first timer being overwritten.

A better solution than a single global variable holding the timer is for every touched object to have its own distinct variable holding the timer to be cleared on event end. This quick fix stores a hold_timer in $this.data rather than in the more global settings.hold_timer.

Edit: I initially thought fast touch events could also trigger this but I don't think a touch should ever register prior to its untouch other than due to propagation so I think this fix 100% solves the problem.

Fix:
Change line 250:
settings.hold_timer = window.setTimeout(function () {
To:
$this.data( 'hold_timer', window.setTimeout(function () {

Change line 289:
}, threshold);
To:
}, threshold) );

Change line 296:
window.clearTimeout(settings.hold_timer);
To:
window.clearTimeout($this.data( 'hold_timer' ));

Remove line 52 (optional):
hold_timer: null,

@benmajor
Copy link
Owner

benmajor commented Dec 2, 2019

Thanks for the heads-up, @dustinbolton. I have now added this fix to the 2.0.1 release (see 9a6e4c6)

Thanks for suggestion!

@benmajor benmajor closed this as completed Dec 2, 2019
@benmajor benmajor self-assigned this Dec 2, 2019
@benmajor benmajor added the bug The issue outlines a clear bug in the existing code which needs to be fixed now, or next release. label Dec 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue outlines a clear bug in the existing code which needs to be fixed now, or next release.
Projects
None yet
Development

No branches or pull requests

2 participants