Skip to content

Bangle.js2 emulator: implement touchscreen long-touch gesture#311

Open
mdoggydog wants to merge 1 commit intoespruino:masterfrom
mdoggydog:mdog-emu-long-press
Open

Bangle.js2 emulator: implement touchscreen long-touch gesture#311
mdoggydog wants to merge 1 commit intoespruino:masterfrom
mdoggydog:mdog-emu-long-press

Conversation

@mdoggydog
Copy link
Copy Markdown

This change incorporates the MIT-licensed "long-press-event" library from https://github.com/john-doherty/long-press-event, and uses its default delay of 1.5 seconds.

(1.5 seconds seemed about right, but I did not try to time it accurately. If anyone knows the actual delay used by the hardware device, I can adjust the delay accordingly.)

This change incorporates the MIT-licensed "long-press-event" library from
https://github.com/john-doherty/long-press-event, and uses its default delay
of 1.5 seconds.
@gfwilliams
Copy link
Copy Markdown
Member

Thanks! Is it possible to just implement this with a setTimeout or checking the time in the code though? I'm not a big fan of pulling in external libraries for something that could have been done pretty simply otherwise.

Doing it ourselves would also allow us to respond to the length of the button press - do your 'long-press' code for a medium press, and trigger a reload for a longer press (like the real watch)

@mdoggydog
Copy link
Copy Markdown
Author

Thanks! Is it possible to just implement this with a setTimeout or checking the time in the code though? I'm not a big fan of pulling in external libraries for something that could have been done pretty simply otherwise.

When I poked around looking for approaches to detecting long-presses, the impression I got was that (a) yes, you pretty much use setTimeout, but (b) there are complications from things like ensuring that the timeout is canceled in all the appropriate circumstances, on various browsers, etc. The library I found and pulled in appears to do that, and it was pretty compact. So, I figure, this thing has already had quirks worked out of it for 9 years; better to just take advantage of that than to start diagnosing broken long-press events from scratch, and eventually ending up in the same place anyway.

Doing it ourselves would also allow us to respond to the length of the button press - do your 'long-press' code for a medium press, and trigger a reload for a longer press (like the real watch)

Keep in mind that this is for the touchscreen emulation, not BTN1, and there is (AFAIK) only one kind of long-press emitted by the touchscreen. But, if you mean using this browser-side long-press detection to also do something about the BTN1 events... maybe there is some relatively simple way to get multiple, different-duration events from this code?... haven't thought about that yet...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants