Hello, I was trying to use the back handling on bo...
# compose-desktop
d
Hello, I was trying to use the back handling on both android and desktop, I think the
BackHandler
should be ported to
desktop
and
web
as well as we can use the buttons to go back (I use mouse buttons to navigate on desktop). I was writing a multiplatform navigation component and it needs multiplatform
BackHandler
, I have an expect/actual for that, but it would be great for it to be part of the
compose
library
h
Web is easy, but how should it work on desktop? Not everybody has decided mouse buttons
d
I also have back and forward buttons on my keyboard, I think there are enough people using them to consider implementing this. Just like IDEA, I use my mouse buttons to go back and forth in the code. I would like to navigate back using these buttons. I also have a file tree made in compose to open files, and being able to navigate the backstack of that would be nice.
h
Feel free to implement it using Swing key observer, but I would not expect a default solution because these keys are not available by default (eg Apple Keyboard).
d
I used Android Studio on macOs with a mouse that has these buttons and it worked, so I think it should work.
k
I'd be really careful about trying to force interaction paradigms from one platform (Android) on a completely different one (desktop). Off the top of my head, I can't even think of a single desktop app that I use on the daily basis that has anything that I'd even call navigation. I guess you can see editor tabs in IntelliJ and link clicking in the browser as navigation of a sort. Maybe? Kinda a stretch.
👍 3
n
IntelliJ actually has a pretty robust backward-forward system that I use regularly. As you Ctrl+Click to jump between locations, it builds up a back stack which you can access with Alt+Shift+Left and Alt+Shift+Right. The result is that following symbols ends up feeling very similar to following links in a browser. That said, I wholeheartedly agree that this doesn't need to be in the standard compose library. This is very app-specific functionality, and most desktop apps don't use anything resembling that paradigm.
👍🏻 1
👍 1
k
This would be a good option. Windows Explorer (files/folders) and Internet Browsers I always use my mouse back and forward buttons to speedily navigate.
n
The reason why
BackHandler
exists on Android is because it's the only built-in navigation button that isn't handled by the operating system (ignoring a few apps that hijack the volume keys for navigation). All other interactivity is actually defined on-screen by the app itself, so it doesn't need a separate handler. On web and desktop, by contrast, there are tons of keys and key combos that are used for navigation. It would be hard to justify having a dedicated
BackHandler
without also having a
LeftKeyHandler
and a
RightKeyHandler
and a
ShiftEnterHandler
, etc. If something like this were to be a part of Compose for Web or for Desktop, it would need to be a generic
KeypressHandler
and/or
MouseButtonHandler
in order to make sense. On web this is already trivial to achieve with an event handler on
document
. If something similar doesn't exist on Desktop, it probably should, and it would make sense to wrap it in an API that is usable on both. But we don't need a dedicated
BackHandler
.