GianlucaGuarini / Tocca.js

Super lightweight script (~1kb) to detect via Javascript events like 'tap' 'dbltap' 'swipeup' 'swipedown' 'swipeleft' 'swiperight' on any kind of device.
http://gianlucaguarini.github.io/Tocca.js/
MIT License
661 stars 61 forks source link

iOS 8 tap issues #11

Closed akrymski closed 9 years ago

akrymski commented 9 years ago

Thanks for an awesome library, I've been using something similar that I wrote myself for https://github.com/techlayer/espresso.js

Was wondering why the tap event isn't firing immediately after a touchEnd, but instead waits 200ms? Can't seem to wrap my head around that design decision, but you must have a reason.

On iOS 8 both a tap and a click event seem to get fired. Check this thread: https://github.com/ftlabs/fastclick/issues/262

This article sheds some light on the iOS 8 issues: http://developer.telerik.com/featured/300-ms-click-delay-ios-8/

while the delay is still in place for “fast taps”, it has been removed for “slow taps”

GianlucaGuarini commented 9 years ago

The tap event is fired after 200ms because otherwise I cannot detect the dbltap events. In any case you can change this behavior by changing this option

akrymski commented 9 years ago

That's what I figured. Unfortunately in Phonegap on IOS 8 if you hold for over 200ms no tap event is fired. Only quick taps seem to work.

On 4 Feb 2015, at 22:47, Gianluca Guarini notifications@github.com wrote:

The tap event is fired after 200ms because otherwise I cannot detect the dbltap events. In any case you can change this behavior by changing this option

— Reply to this email directly or view it on GitHub.

GianlucaGuarini commented 9 years ago

And that's what a tap event it's supposed to be! If you hold your finger It's not a tap anymore so it works perfectly. If you want to change this behavior you can change the window.TAP_TRESHOLD I am going to close this that seems to be not a bug

akrymski commented 9 years ago

can’t agree with that. apps listen to tap events instead of click events. so if my tap takes longer than 200ms i can’t detect it anymore? that’s clearly a bug to me. and TAP_THRESHOLD doesn’t fix that, as if you make it 300ms then the tap delay is as slow as the click delay. In fact 200ms isn’t even much faster than the 300ms delay you get with native click behaviour. That’s not how any of the other libs like FastClick work for example.

I’m pretty sure you can still detect double taps if you listen to touchend instead of touchstart. Two touchend events within a certain time threshold can be considered a double tap. That makes more sense to me than having a timeout listening to touchstart, unless I’m missing something.

On 4 Feb 2015, at 23:40, Gianluca Guarini notifications@github.com wrote:

And that's what's supposed to be a tap event! If you hold your finger It's not a tap anymore so it works perfectly. If you want to change this behavior you can change the window.TAP_TRESHOLD I am going to close this that seems to be not a bug

— Reply to this email directly or view it on GitHub.

GianlucaGuarini commented 9 years ago

Ok It sounds a good idea, I will try the other way around using the touchend events to see if I can enhance it

GianlucaGuarini commented 9 years ago

Let me know if now it works better

akrymski commented 9 years ago

Looks better, but still not sure if setTimeout is at all necessary. You could just fire a tap event on touchEnd. And if there's another tap within 200ms then also fire a double-tap.

I believe this is more inline with how iOS Gesture Recognizer works:

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITapGestureRecognizer_Class/index.html#//apple_ref/occ/cl/UITapGestureRecognizer

Although taps are discrete gestures, they are discrete for each state of the gesture recognizer; thus the associated action message is sent when the gesture begins and is sent for each intermediate state until (and including) the ending state of the gesture.

GianlucaGuarini commented 9 years ago

Ok it makes sense to trigger first a tap and eventually a dbltap. I will make a new release soon, thanks for your help