Skip to content

Commit

Permalink
Incorporate @s0meone's fix for duplicate tap events
Browse files Browse the repository at this point in the history
I meant to do this originally, but failed to notice his work was on
a different branch.
  • Loading branch information
appsforartists committed Sep 16, 2014
1 parent 13be341 commit 2389350
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/TapEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,24 @@ var topLevelTypes = EventConstants.topLevelTypes;
var isStartish = EventPluginUtils.isStartish;
var isEndish = EventPluginUtils.isEndish;

var isTouch = function(topLevelType) {
var touchTypes = [
topLevelTypes.topTouchCancel,
topLevelTypes.topTouchEnd,
topLevelTypes.topTouchStart,
topLevelTypes.topTouchMove
];
return touchTypes.indexOf(topLevelType) >= 0;
}

/**
* Number of pixels that are tolerated in between a `touchStart` and `touchEnd`
* in order to still be considered a 'tap' event.
*/
var tapMoveThreshold = 10;
var ignoreMouseThreshold = 750;
var startCoords = {x: null, y: null};
var lastTouchEvent = null;

var Axis = {
x: {page: 'pageX', client: 'clientX', envScroll: 'currentPageScrollLeft'},
Expand Down Expand Up @@ -92,6 +104,8 @@ var TapEventPlugin = {

tapMoveThreshold: tapMoveThreshold,

ignoreMouseThreshold: ignoreMouseThreshold,

eventTypes: eventTypes,

/**
Expand All @@ -107,6 +121,15 @@ var TapEventPlugin = {
topLevelTarget,
topLevelTargetID,
nativeEvent) {

if (isTouch(topLevelType)) {
lastTouchEvent = nativeEvent.timeStamp;
} else {
if (lastTouchEvent && (nativeEvent.timeStamp - lastTouchEvent) < ignoreMouseThreshold) {
return null;
}
}

if (!isStartish(topLevelType) && !isEndish(topLevelType)) {
return null;
}
Expand All @@ -132,4 +155,4 @@ var TapEventPlugin = {

};

module.exports = TapEventPlugin;
module.exports = TapEventPlugin;

0 comments on commit 2389350

Please sign in to comment.