From 2389350251b83bf6ab1152341eb6cc165aba3e31 Mon Sep 17 00:00:00 2001 From: Brenton Simpson Date: Tue, 16 Sep 2014 16:17:22 -0700 Subject: [PATCH] Incorporate @s0meone's fix for duplicate tap events I meant to do this originally, but failed to notice his work was on a different branch. --- src/TapEventPlugin.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/TapEventPlugin.js b/src/TapEventPlugin.js index 71230cd50b24d..5af298e8963af 100644 --- a/src/TapEventPlugin.js +++ b/src/TapEventPlugin.js @@ -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'}, @@ -92,6 +104,8 @@ var TapEventPlugin = { tapMoveThreshold: tapMoveThreshold, + ignoreMouseThreshold: ignoreMouseThreshold, + eventTypes: eventTypes, /** @@ -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; } @@ -132,4 +155,4 @@ var TapEventPlugin = { }; -module.exports = TapEventPlugin; +module.exports = TapEventPlugin; \ No newline at end of file