1

I am programming a highly responsive web application and came across the issue that most time is used to recognize double taps.

I am using this code from the website:

var singleTap = new Hammer.Tap({ event: 'singletap' });
var doubleTap = new Hammer.Tap({event: 'doubletap', taps: 2 });

hammer.add([doubleTap, singleTap]);
doubleTap.recognizeWith(singleTap);
singleTap.requireFailure(doubleTap);

This basically works quite fine. However, due to the timeouts/intervals the recognition of a double tap takes quite "long". I guess its about 2 times the interval - one for each tap.

The waiting for the last interval (waiting for a third tap) is senseless in my scenario. Is there any "ok tapCount == 2, we fire now and don't wait any longer"-TapRecognizer option?

Update, I have done some logging:

First column: passed ms since first event

  • 0 input: mousedown

  • 74ms input: mouseup

  • 145ms input: mousedown

  • 218ms input: mouseup

  • 520ms double tap

-

  • 0 input: mousedown

  • 64ms input: mouseup

  • 366ms single tap

This confirms my theory that double tap is waiting for a third click but I don't think there's an option to disable this.

2 Answers 2

1

I share my solution to the problem:

I copied the TapRecognizer and named it DblTapRecognizer. The interesting source code lines are:

if (tapCount === 0) {
    // no failing requirements, immediately trigger the tap event
    // or wait as long as the multitap interval to trigger
    if (!this.hasRequireFailures()) {
        return STATE_RECOGNIZED;
    } else {
        this._timer = setTimeoutContext(function() {
            this.state = STATE_RECOGNIZED;
            this.tryEmit();
        }, options.interval, this);
        return STATE_BEGAN;
    }
}

"if (!this.hasRequireFailures())" seems to misbehave in my situation, since the comment hints at immediate firing... So just "return STATE_RECOGNIZED;" and delete the rest for the DblTapRecognizer.

0

We ran into similar slowness issues. Apparently there is an inherent lag on tap action on touch devices.

We ended up using FastClick

All you need to do is FastClick.attach(document.body); This improved the "tap performance" for us.

3
  • Thank you for the answer. Seems to be a bit faster on tablets.However, I am still encountering this on desktop browsers.
    – starY
    Commented Jan 12, 2015 at 8:48
  • "tap" events are for touch devices and "click" for desktops.. I wonder if you trying to get the TAP event on a desktop device. Commented Jan 14, 2015 at 8:36
  • Hammer.js luckily abstracts from those events :)
    – starY
    Commented Jan 15, 2015 at 14:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.