From e5c65b30670e7dee62fd6ecc816345c0de2672e6 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Tue, 19 Sep 2017 08:00:29 -0700 Subject: [PATCH] Set touchstart listener to 'passive', remove 'once' (#5011) --- app/javascript/mastodon/is_mobile.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/javascript/mastodon/is_mobile.js b/app/javascript/mastodon/is_mobile.js index e9903d59e..dbdb30081 100644 --- a/app/javascript/mastodon/is_mobile.js +++ b/app/javascript/mastodon/is_mobile.js @@ -1,3 +1,5 @@ +import detectPassiveEvents from 'detect-passive-events'; + const LAYOUT_BREAKPOINT = 1024; export function isMobile(width) { @@ -5,11 +7,16 @@ export function isMobile(width) { }; const iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream; -let userTouching = false; -window.addEventListener('touchstart', () => { +let userTouching = false; +let listenerOptions = detectPassiveEvents.hasSupport ? { passive: true } : false; + +function touchListener() { userTouching = true; -}, { once: true }); + window.removeEventListener('touchstart', touchListener, listenerOptions); +} + +window.addEventListener('touchstart', touchListener, listenerOptions); export function isUserTouching() { return userTouching;