Hi, I was using Backhandler in CMP and now it says...
# compose
s
Hi, I was using Backhandler in CMP and now it says it deprecated, do anyone know how to use this NavigationEventHandler or any docs related to it.
i
The documentation for NavigationEventHandler work on all platforms: https://developer.android.com/guide/navigation/navigation-event/handle-back
d
Is there any guidance on how to make predictive back/NavigationEventHandler with "Are you sure" type of confirmation dialogs? For example when the user is filling a form and you don't want them to accidentally lose all their progress?
i
I think quite a few designers have moved away from confirmation dialogs in general, but instead use patterns like snackbars to undo accidental actions (e.g., you let them navigate back, but keep the data around until the snackbar goes away in case they want to go back to it): https://proandroiddev.com/implementing-snackbar-to-undo-actions-in-jetpack-compose-7b8ec92cf8a7 Of course, that's a lot harder than doing a confirmation dialog, so you can certainly still use that pattern - just show the dialog in
onBackCompleted
and figure out if there's something that would be appropriate to animate (does your 'submit' button morph into a 'discard' button during the predictive back?)
d
Thank you! I'll see if using a snackbar is something our design team is willing to adopt. iOS 26 has a similar back gesture so it shouldn't be hard to get backing from the iOS team either, although I'm guessing they won't be too keen on snackbars given it's quite an android concept.
i
Sure, you'd want to pick the right platform specific UI pattern. Maybe alert dialogs are still the right pattern for iOS users if they don't know anything different