[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
This commit is contained in:
Nicolas Gallagher
2018-02-12 09:10:20 -08:00
parent 748b2d0f3f
commit 9ee89bc7f7
@@ -39,16 +39,26 @@ ResponderEventPlugin.eventTypes.selectionChangeShouldSetResponder.dependencies =
ResponderEventPlugin.eventTypes.scrollShouldSetResponder.dependencies = [topScroll];
ResponderEventPlugin.eventTypes.startShouldSetResponder.dependencies = startDependencies;
const originalRecordTouchTrack = ResponderTouchHistoryStore.recordTouchTrack;
ResponderTouchHistoryStore.recordTouchTrack = (topLevelType, nativeEvent) => {
// Filter out mouse-move events when the mouse button is not down
if (topLevelType === topMouseMove && !ResponderTouchHistoryStore.touchHistory.touchBank.length) {
const originalExtractEvents = ResponderEventPlugin.extractEvents;
ResponderEventPlugin.extractEvents = (topLevelType, targetInst, nativeEvent, nativeEventTarget) => {
const hasActiveTouches = ResponderTouchHistoryStore.touchHistory.numberActiveTouches > 0;
if (
// Filter out mousemove events when there hasn't been a touch yet
(topLevelType === topMouseMove && !hasActiveTouches) ||
// Filter out events from wheel/middle and right click.
(nativeEvent.button === 1 || nativeEvent.button === 2)
) {
return;
}
const normalizedEvent = normalizeNativeEvent(nativeEvent);
originalRecordTouchTrack.call(ResponderTouchHistoryStore, topLevelType, normalizedEvent);
return originalExtractEvents.call(
ResponderEventPlugin,
topLevelType,
targetInst,
normalizedEvent,
nativeEventTarget
);
};
EventPluginHub.injection.injectEventPluginsByName({