From c3cbd53a8a32367a16f7cdfde264ddcd40d95876 Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Sat, 22 Sep 2018 16:27:06 -0700 Subject: [PATCH] [fix] ResponderEventPlugin removal of emulated mouse events If the work related to a touch/press event takes a long enough time (i.e., CPU intensive, old device, etc.) the browser may produce emulated mouse events >500ms after the original touch event. This causes the related Responder events to fire twice. To avoid that happening, this patch increases the filter threshold used by the ResponderEventPlugin from 200ms to 1000ms. Fix #1078 --- .../src/modules/ResponderEventPlugin/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/react-native-web/src/modules/ResponderEventPlugin/index.js b/packages/react-native-web/src/modules/ResponderEventPlugin/index.js index e3d72fc7..fea5118b 100644 --- a/packages/react-native-web/src/modules/ResponderEventPlugin/index.js +++ b/packages/react-native-web/src/modules/ResponderEventPlugin/index.js @@ -44,6 +44,9 @@ if (!ResponderEventPlugin.eventTypes.responderMove.dependencies) { } let lastActiveTouchTimestamp = null; +// The length of time after a touch that we ignore the browser's emulated mouse events +// https://developer.mozilla.org/en-US/docs/Web/API/Touch_events/Using_Touch_Events +const EMULATED_MOUSE_THERSHOLD_MS = 1000; const originalExtractEvents = ResponderEventPlugin.extractEvents; ResponderEventPlugin.extractEvents = (topLevelType, targetInst, nativeEvent, nativeEventTarget) => { @@ -55,7 +58,7 @@ ResponderEventPlugin.extractEvents = (topLevelType, targetInst, nativeEvent, nat lastActiveTouchTimestamp = Date.now(); } else if (lastActiveTouchTimestamp && eventType.indexOf('mouse') > -1) { const now = Date.now(); - shouldSkipMouseAfterTouch = now - lastActiveTouchTimestamp < 250; + shouldSkipMouseAfterTouch = now - lastActiveTouchTimestamp < EMULATED_MOUSE_THERSHOLD_MS; } if (