Skip to content

Commit ff12423

Browse files
Tienchaizpao
authored andcommitted
Fixing touch/mouse issues with TapEventPlugin
On ios device, browser simulates mouse events, but does that with a delay, because of double tap gesture. The problem is that TapEventPlugins listens to both types of events, so it fires twice Everytime there is a touch event, we should ignore mouse events that follow it. This way, we still respond to both mouse and touch events, just ignore the device generated ones.
1 parent 1c241b3 commit ff12423

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

src/browser/eventPlugins/TapEventPlugin.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,15 @@ var dependencies = [
6262
topLevelTypes.topMouseUp
6363
];
6464

65+
var touchDependencies = [
66+
topLevelTypes.topTouchStart,
67+
topLevelTypes.topTouchCancel,
68+
topLevelTypes.topTouchEnd,
69+
topLevelTypes.topTouchMove
70+
];
71+
6572
if (EventPluginUtils.useTouchEvents) {
66-
dependencies.push(
67-
topLevelTypes.topTouchCancel,
68-
topLevelTypes.topTouchEnd,
69-
topLevelTypes.topTouchStart,
70-
topLevelTypes.topTouchMove
71-
);
73+
dependencies = dependencies.concat(touchDependencies);
7274
}
7375

7476
var eventTypes = {
@@ -81,6 +83,10 @@ var eventTypes = {
8183
}
8284
};
8385

86+
var usedTouch = false;
87+
var usedTouchTime = 0;
88+
var TOUCH_DELAY = 500;
89+
8490
var TapEventPlugin = {
8591

8692
tapMoveThreshold: tapMoveThreshold,
@@ -103,6 +109,17 @@ var TapEventPlugin = {
103109
if (!isStartish(topLevelType) && !isEndish(topLevelType)) {
104110
return null;
105111
}
112+
// on ios, there is a delay after touch event and synthetic
113+
// mouse events, so that user can perform double tap
114+
// solution: ignore mouse events following touchevent within small timeframe
115+
if (touchDependencies.indexOf(topLevelType) !== -1) {
116+
usedTouch = true;
117+
usedTouchTime = Date.now();
118+
} else {
119+
if (usedTouch && (Date.now() - usedTouchTime < TOUCH_DELAY)) {
120+
return;
121+
}
122+
}
106123
var event = null;
107124
var distance = getDistance(startCoords, nativeEvent);
108125
if (isEndish(topLevelType) && distance < tapMoveThreshold) {

0 commit comments

Comments
 (0)