-
• #2
Is there a way to block or clear existing events,
Well, if apps use
Bangle.setUI
then the handlers are all stored: https://github.com/espruino/Espruino/blob/master/libs/js/banglejs/Bangle_setUI_Q3.js#L12-L31So potentially you could find those, remove them and re-add them after... But there is no way of flagging that an event is handled and shouldn't be propagated at the moment. If there's a sensible way to do this I could maybe include this in the firmware though
-
• #3
In my sensortools I override the .on and .removeListener methods, but that is only for debugging purposes. I suspect too much overhead to do that in possibly multiple libs.
Maybe a fast low level function to get all listeners for specific event and a small module in js to handle storing/restoring them would work and be flexible enough. -
• #4
You can get/set all the handlers pretty easily with
E["#onfoo"]
without, so yes a library to handle that would work pretty well -
• #5
This seems to work (in the emulator at least):
function removeListeners(events) { saved = {}; events.forEach(event=>{ let listeners = Bangle['#on'+event]; if (!listeners) return; saved[event] = listeners; Bangle.removeAllListeners(event); }); return saved; } function restoreListeners(saved) { for (const event in saved) { let listeners = saved[event]; if (typeof listeners !== 'object') listeners = [listeners]; listeners.forEach(listener => Bangle.on(event, listener)); delete saved[event]; } } // disable event listeners const eventsToRemove = ['touch','swipe','drag','stroke','tap','gesture','aiGesture']; let saved = removeListeners(eventsToRemove); // do Stuff // when done: restoreListeners(saved);
Hello awesome Banglers!
I have a couple of projects on the go, Hiding the widget bar in an overlay, and Pop up notifications in an overlay, both using
Bangle.SetLCDOverlay
. I'm having trouble with swipes and drags. I can set a new event handler to move the overlay, but the clock face or app underneath also reacts to the swipe or drag.Is there a way to block or clear existing events, e.g.
Bangle.on('swipe'...)
, use my customswipe
handler, then clear my custom handler and put the previous one back?