Skip to content

Commit c83bc99

Browse files
committed
set touchstart/touchmove event as non-passive
1 parent 2a2aab2 commit c83bc99

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

js/rpg_core/TouchInput.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,13 @@ Object.defineProperty(TouchInput, 'date', {
250250
* @private
251251
*/
252252
TouchInput._setupEventHandlers = function() {
253+
var isSupportPassive = Utils.isSupportPassive();
253254
document.addEventListener('mousedown', this._onMouseDown.bind(this));
254255
document.addEventListener('mousemove', this._onMouseMove.bind(this));
255256
document.addEventListener('mouseup', this._onMouseUp.bind(this));
256257
document.addEventListener('wheel', this._onWheel.bind(this));
257-
document.addEventListener('touchstart', this._onTouchStart.bind(this));
258-
document.addEventListener('touchmove', this._onTouchMove.bind(this));
258+
document.addEventListener('touchstart', this._onTouchStart.bind(this), isSupportPassive ? {passive: false} : false);
259+
document.addEventListener('touchmove', this._onTouchMove.bind(this), isSupportPassive ? {passive: false} : false);
259260
document.addEventListener('touchend', this._onTouchEnd.bind(this));
260261
document.addEventListener('touchcancel', this._onTouchCancel.bind(this));
261262
document.addEventListener('pointerdown', this._onPointerDown.bind(this));

js/rpg_core/Utils.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,27 @@ Utils.rgbToCssColor = function(r, g, b) {
131131
Utils._id = 1;
132132
Utils.generateRuntimeId = function(){
133133
return Utils._id++;
134-
};
134+
};
135+
136+
Utils._supportPassiveEvent = null;
137+
/**
138+
* Test this browser support passive event feature
139+
*
140+
* @static
141+
* @method isSupportPassiveEvent
142+
* @return {Boolean} this browser support passive event or not
143+
*/
144+
Utils.isSupportPassiveEvent = function() {
145+
if (typeof Utils._supportPassiveEvent === "boolean") {
146+
return Utils._supportPassiveEvent;
147+
}
148+
// test support passive event
149+
// https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md#feature-detection
150+
var passive = false;
151+
var options = Object.defineProperty({}, "passive", {
152+
get() { passive = true; }
153+
});
154+
window.addEventListener("test", null, options);
155+
Utils._supportPassiveEvent = passive;
156+
return passive;
157+
}

0 commit comments

Comments
 (0)