adrielcafe / voyager

🛸 A pragmatic navigation library for Jetpack Compose
https://voyager.adriel.cafe
MIT License
2.59k stars 137 forks source link

Handling back press with a popup window #198

Closed blonsky95 closed 1 year ago

blonsky95 commented 1 year ago

Hi, I recently added Voyager into my project to handle navigations. I also needed handling back presses so I am giving it a go using this: https://voyager.adriel.cafe/back-press

I find it useful to handle back presses that affect navigation at top level hierarchy. However what if I have a screen that opens an alert window (or popup) and I want back press to be one of: A) Ignored B) detected at composable level (like a BackHandler) so I can dismiss the dialog

Right now the back button is handled at top level so it doesnt care if a dialog is open, it will have the same behaviour as when there is no dialog.

Is there a different way to handle this? Or is there more documentation on back presses I am missing?

Syer10 commented 1 year ago

Voyager just hooks into the Android BackHandler, so you can make your own BackHandler { // my action }, Backhandlers further down in the composable tree have priority.

blonsky95 commented 1 year ago

Yeah so I understand what you would do is create an expect BackHandler and have android implement its own actual BackHandler, and ios to do nothing, yeah makes sense!