diff --git a/src/modules/injectResponderEventPlugin.js b/src/modules/injectResponderEventPlugin.js index 951b3ed5..adbe2a8a 100644 --- a/src/modules/injectResponderEventPlugin.js +++ b/src/modules/injectResponderEventPlugin.js @@ -2,7 +2,6 @@ import EventConstants from 'react/lib/EventConstants' import EventPluginRegistry from 'react/lib/EventPluginRegistry' -import ExecutionEnvironment from 'fbjs/lib/ExecutionEnvironment' import ResponderEventPlugin from 'react/lib/ResponderEventPlugin' import ResponderTouchHistoryStore from 'react/lib/ResponderTouchHistoryStore' import normalizeNativeEvent from './normalizeNativeEvent' @@ -19,14 +18,9 @@ const { topTouchStart } = EventConstants.topLevelTypes -const supportsTouch = ExecutionEnvironment.canUseDOM && ( - 'ontouchstart' in window || - window.DocumentTouch && document instanceof window.DocumentTouch -) - -const endDependencies = supportsTouch ? [ topTouchCancel, topTouchEnd ] : [ topMouseUp ] -const moveDependencies = supportsTouch ? [ topTouchMove ] : [ topMouseMove ] -const startDependencies = supportsTouch ? [ topTouchStart ] : [ topMouseDown ] +const endDependencies = [ topTouchCancel, topTouchEnd, topMouseUp ] +const moveDependencies = [ topTouchMove, topMouseMove ] +const startDependencies = [ topTouchStart, topMouseDown ] /** * Setup ResponderEventPlugin dependencies @@ -51,7 +45,15 @@ ResponderTouchHistoryStore.recordTouchTrack = (topLevelType, nativeEvent) => { if ((topLevelType === topMouseMove) && !ResponderTouchHistoryStore.touchHistory.touchBank.length) { return } - originalRecordTouchTrack.call(ResponderTouchHistoryStore, topLevelType, normalizeNativeEvent(nativeEvent)) + // Cancel mouse events that browsers fire after touch events + if (topLevelType === topTouchStart || topLevelType === topTouchMove || topLevelType === topTouchEnd) { + if (nativeEvent.target.getAttribute('href') !== undefined) { + nativeEvent.preventDefault() + } + } + + const normalizedEvent = normalizeNativeEvent(nativeEvent) + originalRecordTouchTrack.call(ResponderTouchHistoryStore, topLevelType, normalizedEvent) } EventPluginRegistry.injectEventPluginsByName({ diff --git a/src/modules/normalizeNativeEvent.js b/src/modules/normalizeNativeEvent.js index 7a6e5f05..4954568d 100644 --- a/src/modules/normalizeNativeEvent.js +++ b/src/modules/normalizeNativeEvent.js @@ -33,7 +33,7 @@ function normalizeTouchEvent(nativeEvent) { const event = { changedTouches, - domEvent: nativeEvent, + originalEvent: nativeEvent, pageX: nativeEvent.pageX, pageY: nativeEvent.pageY, target: nativeEvent.target, @@ -67,14 +67,14 @@ function normalizeMouseEvent(nativeEvent) { screenX: nativeEvent.screenX, screenY: nativeEvent.screenY, target: nativeEvent.target, - timestamp: nativeEvent.timestamp || Date.now() + timestamp: Date.now() }] return { changedTouches: touches, - domEvent: nativeEvent, identifier: touches[0].identifier, locationX: nativeEvent.offsetX, locationY: nativeEvent.offsetY, + originalEvent: nativeEvent, pageX: nativeEvent.pageX, pageY: nativeEvent.pageY, target: nativeEvent.target, @@ -84,7 +84,8 @@ function normalizeMouseEvent(nativeEvent) { } function normalizeNativeEvent(nativeEvent) { - const mouse = nativeEvent.type.indexOf('mouse') >= 0 + const eventType = nativeEvent.type || (nativeEvent.originalEvent && nativeEvent.originalEvent.type) || '' + const mouse = eventType.indexOf('mouse') >= 0 return mouse ? normalizeMouseEvent(nativeEvent) : normalizeTouchEvent(nativeEvent) }