Skip to content

Commit

Permalink
Make touch events passive like mouse events (#4279)
Browse files Browse the repository at this point in the history
* Make touch events passive like mouse events

Prevent console messages like:

  [Violation] Added non-passive event listener to a scroll-blocking 'touchmove' event. Consider marking event handler as 'passive' to make the page more responsive. See https://www.chromestatus.com/feature/5745543795965952

See also: https://github.com/playcanvas/engine/blob/9a0697c6b2cd521db510df49f90028f414006696/src/input/element-input.js#L421-L426

* Update touch-device.js

Co-authored-by: Will Eastcott <will@playcanvas.com>
  • Loading branch information
erikdubbelboer and willeastcott authored May 31, 2022
1 parent 95c4ecf commit 1ebfd36
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/input/touch-device.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { platform } from '../core/platform.js';
import { EventHandler } from '../core/event-handler.js';

import { TouchEvent } from './touch-event.js';
Expand Down Expand Up @@ -40,10 +41,11 @@ class TouchDevice extends EventHandler {

this._element = element;

this._element.addEventListener('touchstart', this._startHandler, false);
this._element.addEventListener('touchend', this._endHandler, false);
this._element.addEventListener('touchmove', this._moveHandler, false);
this._element.addEventListener('touchcancel', this._cancelHandler, false);
const opts = platform.passiveEvents ? { passive: true } : false;
this._element.addEventListener('touchstart', this._startHandler, opts);
this._element.addEventListener('touchend', this._endHandler, opts);
this._element.addEventListener('touchmove', this._moveHandler, opts);
this._element.addEventListener('touchcancel', this._cancelHandler, opts);
}

/**
Expand Down

0 comments on commit 1ebfd36

Please sign in to comment.