From 02e250cd04c2f030d94a0c5c5d54edc04e5b07a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Lov=C3=A9n?= Date: Wed, 28 Aug 2019 22:37:30 +0200 Subject: [PATCH] Fix for double taps in iOS 13 beta (#3523) See home-assistant/home-assistant-polymer#3510 for more info. --- .../common/directives/long-press-directive.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/panels/lovelace/common/directives/long-press-directive.ts b/src/panels/lovelace/common/directives/long-press-directive.ts index 09f68e5faa..ea76f81788 100644 --- a/src/panels/lovelace/common/directives/long-press-directive.ts +++ b/src/panels/lovelace/common/directives/long-press-directive.ts @@ -136,8 +136,16 @@ class LongPress extends HTMLElement implements LongPress { element.addEventListener("touchstart", clickStart, { passive: true }); element.addEventListener("touchend", clickEnd); element.addEventListener("touchcancel", clickEnd); - element.addEventListener("mousedown", clickStart, { passive: true }); - element.addEventListener("click", clickEnd); + + // iOS 13 sends a complete normal touchstart-touchend series of events followed by a mousedown-click series. + // That might be a bug, but until it's fixed, this should make long-press work. + // If it's not a bug that is fixed, this might need updating with the next iOS version. + // Note that all events (both touch and mouse) must be listened for in order to work on computers with both mouse and touchscreen. + const isIOS13 = window.navigator.userAgent.match(/iPhone OS 13_/); + if (!isIOS13) { + element.addEventListener("mousedown", clickStart, { passive: true }); + element.addEventListener("click", clickEnd); + } } private startAnimation(x: number, y: number) {