mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-05-19 05:01:18 +00:00
[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:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user