Clearing a specific input-linked callback?

Posted on
  • I think I'm missing something simple with an app I am writing, and my google / ctrl+f skills are failing me.

    If I create an event-linked callback, like

    Bangle.on('touch', (button, xy) => getTouchedKey(keys, xy, resolve));
    

    Is there some way to clear that callback from triggering on touch? I tried making a call to

    Bangle.on('touch', () => {});
    

    but that seems to just add another callback to the event watcher.

    Basically I am popping up a keyboard that responds to touch events, but when the keyboard promise resolves I want to return to a previous UI state. Instead I end up with an invisible keyboard over the previous UI.

    Happy to either get an answer here or be directed to the appropriate documentation if it's out there!

    EDIT: I may have found what I am looking for? In the documentation for Bangle.setUI there's a quote:

    While you could use setWatch/etc manually, the benefit here is that you don't end up with multiple setWatch instances,

    So maybe I need to just figure out how to do this with setUI and that will resolve my problem.

    EDIT: Yes, that did it. I'd like to thank the community for bearing with me while I talk through my problems out loud, :D

    For posterity:

    Bangle.setUI({
          mode: "custom",
          touch: (button, xy) => getTouchedKey(keys, xy, resolve)
        });
    ... later...
    Bangle.setUI(undefined);
    
  • Nicely done working it out 🙂

    Using Bangle.removeListener() you can remove individual listeners you've set yourself. Like this: https://www.espruino.com/Reference#l_Obj­ect_removeListener

    But I think you worked out the better solution using setUI 👍

  • Well done for solving your problem! Not sure if you're aware, but there's a whole selection of keyboards available for the JS2: https://banglejs.com/apps/?c=textinput

    Details of how to use them in your own app here: https://github.com/espruino/BangleApps/t­ree/master/apps/kbtouch

    You might want to repackage your keyboard as a separate app so others can use it, or give people a choice of which keyboard they use to interact with your app.

  • Thanks for mentioning that. I was introduced to the ecosystem only days ago and did not find the existing keyboard libraries! Letting the user select their preferred input method is a great idea.

    I may put my keyboard out there for others if I can distinguish it sufficiently from the existing ones. Right now it's similar to the multi-tap keyboard but with emphasis on speed via reduced character set.

    Looking forward to getting a device in hand so I can do a better ergonomic comparison between what I've made and what's out there!

  • It's a fantastic ecosystem, Gordon has done a smashing job with it! And there is a lot of helpful things out there. When I made my first app I laboriously laid it out by hand, only afterwards did I discover the layout library which made it much easier!

    If the keyboard you've made is your avatar, I also thought it looked similar to the multi-tap keyboard (you may see a familiar name listed under authors in the readme!)

    Using the real device is quite different from the emulator, but please do a comparison when you get your hands on it. If your keyboard works better you can always make changes to the multi-tap keyboard so that everyone can benefit from your improvements, or as you say release a separate keyboard app that suits your needs better. That's one of the joys of open-source, it's up to you.

    But that's only the keyboard section, do you mind if I'm nosy and ask what the rest of your app does?

  • The impetus for me searching for a smart watch was to create a prosthetic device to treat the working memory portion of my ADHD symptoms.

    The idea is to be able to type in what I want to be doing immediately when I decide to go do it. Then the watch will vibrate and remind me at set intervals (thirty seconds, one minute, two minutes, something configurable, maybe with incremental backoff) of that task.

    For example, I might be standing in my bathroom upstairs and notice that I'm hungry, but between the time I say "I'll go make a bowl of cereal" and the time I arrive in the kitchen I am totally sidetracked by something else. Sometimes I don't even make it to the intended part of the house, and I won't remember that I need to eat for another hour or more.

    I'm thinking if I can have something on my wrist that will let me IMMEDIATELY externalize my working memory then I can have a constant tactile reminder of my intention. That's why I'm emphasizing entry speed and de-emphasizing character breadth for my input, because I could type "brkfst" or "car" or "laund" and that would be sufficient.

    There's more to the app than just that, I'm also planning to create a task queue system and a re-prioritization feature where you can put an incomplete task on the back burner if you actually need to switch gears. Other features bouncing around in brain as well but it has fallen into the background while I wait for the device to come in.

    There are devices out there that do this (https://reminderwatch.com/) but most of them are at similar price points with significantly reduced flexibility, and many of them focus on repeating reminders that you set ahead of time. Kinda like they are aware of the problem they are trying to solve but not aware of the root cause of that problem.

  • That sounds like a fantastic idea! I don't have ADHD but I'd love to use that app, I could load it with all the things my wife asks me to do and which I almost instantly forget! Thank you for the example of reminding yourself to eat, you reminded me that we don't all think in the same way, personally I never forget to eat, quite the opposite I'm often thinking about my next meal!

    The task queue with priority sounds great too, currently I might set an alarm to remind me of something, but that's not easy to add multiple things to, and the alarm by definition only goes off at a set time. An occasionally gentle reminder sounds like a better solution.

    Brilliant use of tech to help you out, and nice to see the commercial option you linked, I'm sure you'll be able to make something that works better!

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

Clearing a specific input-linked callback?

Posted by Avatar for Philip @Philip

Actions