Skip to content

Commit

Permalink
Mark which touch/scroll related event listeners are passive (#5511)
Browse files Browse the repository at this point in the history
Co-authored-by: Noeri Huisman <[email protected]>
  • Loading branch information
mrxz and mrxz authored May 23, 2024
1 parent 08fe993 commit d83d7d7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/components/cursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ module.exports.Component = registerComponent('cursor', {
canvas = el.sceneEl.canvas;
if (data.downEvents.length || data.upEvents.length) { return; }
CANVAS_EVENTS.DOWN.forEach(function (downEvent) {
canvas.addEventListener(downEvent, self.onCursorDown);
canvas.addEventListener(downEvent, self.onCursorDown, {passive: false});
});
CANVAS_EVENTS.UP.forEach(function (upEvent) {
canvas.addEventListener(upEvent, self.onCursorUp);
canvas.addEventListener(upEvent, self.onCursorUp, {passive: false});
});
}

Expand Down Expand Up @@ -205,8 +205,8 @@ module.exports.Component = registerComponent('cursor', {
canvas.removeEventListener('touchmove', this.onMouseMove);
el.setAttribute('raycaster', 'useWorldCoordinates', false);
if (this.data.rayOrigin !== 'mouse') { return; }
canvas.addEventListener('mousemove', this.onMouseMove, false);
canvas.addEventListener('touchmove', this.onMouseMove, false);
canvas.addEventListener('mousemove', this.onMouseMove);
canvas.addEventListener('touchmove', this.onMouseMove, {passive: false});
el.setAttribute('raycaster', 'useWorldCoordinates', true);
this.updateCanvasBounds();
},
Expand Down
6 changes: 3 additions & 3 deletions src/components/look-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ module.exports.Component = registerComponent('look-controls', {
window.addEventListener('mouseup', this.onMouseUp, false);

// Touch events.
canvasEl.addEventListener('touchstart', this.onTouchStart);
window.addEventListener('touchmove', this.onTouchMove);
window.addEventListener('touchend', this.onTouchEnd);
canvasEl.addEventListener('touchstart', this.onTouchStart, {passive: true});
window.addEventListener('touchmove', this.onTouchMove, {passive: true});
window.addEventListener('touchend', this.onTouchEnd, {passive: true});

// sceneEl events.
sceneEl.addEventListener('enter-vr', this.onEnterVR);
Expand Down
4 changes: 2 additions & 2 deletions src/components/scene/xr-mode-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ function createOrientationModal (onClick) {
function applyStickyHoverFix (buttonEl) {
buttonEl.addEventListener('touchstart', function () {
buttonEl.classList.remove('resethover');
});
}, {passive: true});
buttonEl.addEventListener('touchend', function () {
buttonEl.classList.add('resethover');
});
}, {passive: true});
}
2 changes: 1 addition & 1 deletion src/core/scene/a-scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ function setupCanvas (sceneEl) {
document.addEventListener('MSFullscreenChange', onFullScreenChange);

// Prevent overscroll on mobile.
canvasEl.addEventListener('touchmove', function (event) { event.preventDefault(); });
canvasEl.addEventListener('touchmove', function (event) { event.preventDefault(); }, {passive: false});

// Set canvas on scene.
sceneEl.canvas = canvasEl;
Expand Down

0 comments on commit d83d7d7

Please sign in to comment.