From c99907bdcd0520b8dbaadcea00393cfeef4c1f27 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Sun, 14 May 2023 18:56:08 +0200 Subject: [PATCH] lightswitch: handle and intercept swipe event --- apps/lightswitch/ChangeLog | 1 + apps/lightswitch/metadata.json | 2 +- apps/lightswitch/widget.js | 16 +++++++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/apps/lightswitch/ChangeLog b/apps/lightswitch/ChangeLog index c4aeb2c1e..4f62ab799 100644 --- a/apps/lightswitch/ChangeLog +++ b/apps/lightswitch/ChangeLog @@ -4,3 +4,4 @@ 0.04: Add masking widget input to other apps (using espruino/Espruino#2151), add a oversize option to increase the touch area. 0.05: Prevent drawing into app area. 0.06: Fix issue where .draw was being called by reference (not allowing widgets to be hidden) +0.07: Handle the swipe event that is generated when draging to change light intensity, so it doesn't trigger some other swipe handler. diff --git a/apps/lightswitch/metadata.json b/apps/lightswitch/metadata.json index d1a8d6e2a..f1f0160b8 100644 --- a/apps/lightswitch/metadata.json +++ b/apps/lightswitch/metadata.json @@ -2,7 +2,7 @@ "id": "lightswitch", "name": "Light Switch Widget", "shortName": "Light Switch", - "version": "0.06", + "version": "0.07", "description": "A fast way to switch LCD backlight on/off, change the brightness and show the lock status. All in one widget.", "icon": "images/app.png", "screenshots": [ diff --git a/apps/lightswitch/widget.js b/apps/lightswitch/widget.js index 922875216..6b573355b 100644 --- a/apps/lightswitch/widget.js +++ b/apps/lightswitch/widget.js @@ -165,13 +165,12 @@ w.changeValue(value, event.b); // masks this drag event by messing up the event handler - // see https://github.com/espruino/Espruino/issues/2151 - Bangle.removeListener("drag", w.dragListener); - Bangle["#ondrag"] = [w.dragListener].concat(Bangle["#ondrag"]); + E.stopEventPropagation&&E.stopEventPropagation(); // on touch release remove drag listener and reset drag status to indicate stopped drag action if (!event.b) { Bangle.removeListener("drag", w.dragListener); + Bangle.removeListener("swipe", w.swipeListener); w.dragStatus = "off"; } @@ -181,6 +180,11 @@ value = undefined; }, + swipeListener: function(_,__) { + // masks this swipe event by messing up the event handler + E.stopEventPropagation&&E.stopEventPropagation(); + }, + // listener function // // touch listener for light control touchListener: function(button, cursor) { @@ -197,12 +201,14 @@ Bangle.buzz(25); // check if drag is disabled if (w.dragDelay) { - // add drag listener at first position + // add drag and swipe listeners at respective first position Bangle["#ondrag"] = [w.dragListener].concat(Bangle["#ondrag"]); + Bangle["#onswipe"] = [w.swipeListener].concat(Bangle["#onswipe"]); // set drag timeout w.dragStatus = setTimeout((w) => { - // remove drag listener + // remove drag and swipe listeners Bangle.removeListener("drag", w.dragListener); + Bangle.removeListener("swipe", w.swipeListener); // clear drag timeout if (typeof w.dragStatus === "number") clearTimeout(w.dragStatus); // reset drag status to indicate stopped drag action