Skip to content

Commit 9ee89bc

Browse files
committedFeb 12, 2018
[fix] ResponderEventPlugin event filtering
Exclude middle, wheel, and right click mouse events from the responder system. This fixes the Touchables incorrectly triggering 'onPress' in response to these events. Filter mousemove events in the 'extractEvents' methods, and check for active touches rather than the length of the touch bank. This fixes the PanResponder not functioning after the first touch in Firefox. Fix #719 Fix #729 Close #804
1 parent 748b2d0 commit 9ee89bc

File tree

1 file changed

+16
-6
lines changed
  • packages/react-native-web/src/modules/injectResponderEventPlugin

1 file changed

+16
-6
lines changed
 

Diff for: ‎packages/react-native-web/src/modules/injectResponderEventPlugin/index.js

+16-6
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,26 @@ ResponderEventPlugin.eventTypes.selectionChangeShouldSetResponder.dependencies =
3939
ResponderEventPlugin.eventTypes.scrollShouldSetResponder.dependencies = [topScroll];
4040
ResponderEventPlugin.eventTypes.startShouldSetResponder.dependencies = startDependencies;
4141

42-
const originalRecordTouchTrack = ResponderTouchHistoryStore.recordTouchTrack;
43-
44-
ResponderTouchHistoryStore.recordTouchTrack = (topLevelType, nativeEvent) => {
45-
// Filter out mouse-move events when the mouse button is not down
46-
if (topLevelType === topMouseMove && !ResponderTouchHistoryStore.touchHistory.touchBank.length) {
42+
const originalExtractEvents = ResponderEventPlugin.extractEvents;
43+
ResponderEventPlugin.extractEvents = (topLevelType, targetInst, nativeEvent, nativeEventTarget) => {
44+
const hasActiveTouches = ResponderTouchHistoryStore.touchHistory.numberActiveTouches > 0;
45+
if (
46+
// Filter out mousemove events when there hasn't been a touch yet
47+
(topLevelType === topMouseMove && !hasActiveTouches) ||
48+
// Filter out events from wheel/middle and right click.
49+
(nativeEvent.button === 1 || nativeEvent.button === 2)
50+
) {
4751
return;
4852
}
4953

5054
const normalizedEvent = normalizeNativeEvent(nativeEvent);
51-
originalRecordTouchTrack.call(ResponderTouchHistoryStore, topLevelType, normalizedEvent);
55+
return originalExtractEvents.call(
56+
ResponderEventPlugin,
57+
topLevelType,
58+
targetInst,
59+
normalizedEvent,
60+
nativeEventTarget
61+
);
5262
};
5363

5464
EventPluginHub.injection.injectEventPluginsByName({

1 commit comments

Comments
 (1)

necolas commented on Feb 13, 2018

@necolas
OwnerAuthor

Note: this patch also fixed #701

Please sign in to comment.