From c819606f9d7092bcaec6811cf5caeb589a290532 Mon Sep 17 00:00:00 2001 From: Kuitos Date: Wed, 1 Mar 2017 15:58:03 +0800 Subject: [PATCH] make tapMoveThreshold configurable, a bit code different with https://github.com/zilverline/react-tap-event-plugin/pull/63 --- src/TapEventPlugin.js | 7 +------ src/injectTapEventPlugin.js | 8 +++++++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/TapEventPlugin.js b/src/TapEventPlugin.js index 672301b14798..fc40247563ac 100644 --- a/src/TapEventPlugin.js +++ b/src/TapEventPlugin.js @@ -42,11 +42,6 @@ var isTouch = function(topLevelType) { 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; @@ -109,7 +104,7 @@ var now = (function() { } })(); -function createTapEventPlugin(shouldRejectClick) { +function createTapEventPlugin(shouldRejectClick, tapMoveThreshold) { return { tapMoveThreshold: tapMoveThreshold, diff --git a/src/injectTapEventPlugin.js b/src/injectTapEventPlugin.js index 807e6d07f752..d8c6a77a044d 100644 --- a/src/injectTapEventPlugin.js +++ b/src/injectTapEventPlugin.js @@ -1,11 +1,17 @@ var invariant = require('fbjs/lib/invariant'); var defaultClickRejectionStrategy = require('./defaultClickRejectionStrategy'); +/** + * Number of pixels that are tolerated in between a `touchStart` and `touchEnd` + * in order to still be considered a 'tap' event. + */ +var defaultTapMoveThreshold = 10; var alreadyInjected = false; module.exports = function injectTapEventPlugin (strategyOverrides) { strategyOverrides = strategyOverrides || {} var shouldRejectClick = strategyOverrides.shouldRejectClick || defaultClickRejectionStrategy; + var tapMoveThreshold = strategyOverrides.tapMoveThreshold || defaultTapMoveThreshold; if (process.env.NODE_ENV !== 'production') { invariant( @@ -21,6 +27,6 @@ should be injected by the application.' alreadyInjected = true; require('react-dom/lib/EventPluginHub').injection.injectEventPluginsByName({ - 'TapEventPlugin': require('./TapEventPlugin.js')(shouldRejectClick) + 'TapEventPlugin': require('./TapEventPlugin.js')(shouldRejectClick, tapMoveThreshold) }); };