Skip to content

Commit

Permalink
Remove 300ms click delay
Browse files Browse the repository at this point in the history
Ensure concurrent registration of single and double tap handlers works properly
  • Loading branch information
ericsoco committed May 19, 2017
1 parent 52ccf74 commit 0f502f7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/utils/events/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const BASIC_EVENT_ALIASES = {
export const EVENT_RECOGNIZER_MAP = {
click: 'tap',
tap: 'tap',
doubletap: 'tap',
doubletap: 'doubletap',
press: 'press',
pinch: 'pinch',
pinchin: 'pinch',
Expand Down Expand Up @@ -80,7 +80,7 @@ export const RECOGNIZERS = [
[Swipe, {enable: false}],
[Press, {enable: false}],
[Tap, {event: 'doubletap', taps: 2, enable: false}],
[Tap, {enable: false}, null, 'doubletap']
[Tap, {enable: false, interval: 0}]
];

/**
Expand Down
24 changes: 24 additions & 0 deletions src/utils/events/event-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ export default class EventManager {
// Enable recognizer for this event.
this.manager.get(recognizerEvent).set({enable: true});

// Handle concurrent single and double tap registration as necessary.
this._reconcileSingleAndDoubleTap(recognizerEvent);

// Alias to a recognized gesture as necessary.
const eventAlias = GESTURE_EVENT_ALIASES[event];
if (eventAlias && !this.aliasedEventHandlers[event]) {
Expand Down Expand Up @@ -140,7 +143,28 @@ export default class EventManager {
this.manager.emit(type, event);
}

/**
* Alias one event name to another,
* to support events supported by Hammer.js under a different name.
* See constants.GESTURE_EVENT_ALIASES.
*/
_aliasEventHandler(eventAlias) {
return event => this.manager.emit(eventAlias, event);
}

/**
* If single and double tap are both enabled,
* The single tap recognizer must wait for the double tap recognizer
* to fail before resolving. Note that enabling both incurs a slight delay
* on tap/click handler resolution.
*/
_reconcileSingleAndDoubleTap(event) {
if (event === 'tap' || event === 'doubletap') {
const singletapRecognizer = this.manager.get('tap');
const doubletapRecognizer = this.manager.get('doubletap');
if (singletapRecognizer.options.enable && doubletapRecognizer.options.enable) {
singletapRecognizer.requireFailure('doubletap');
}
}
}
}

0 comments on commit 0f502f7

Please sign in to comment.