• 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 custom swipe handler, then clear my custom handler and put the previous one back?

  • 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/blo­b/master/libs/js/banglejs/Bangle_setUI_Q­3.js#L12-L31

    So 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

  • 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.

  • You can get/set all the handlers pretty easily with E["#onfoo"] without, so yes a library to handle that would work pretty well

  • 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);
    
    
  • Fab, thanks @rigrig! Looks good, I'll give it a go.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Stop input events, use custom ones, then restore the original?

Posted by Avatar for Sir_Indy @Sir_Indy

Actions