Hi folks. Is there a way to customize back button ...
# compose
d
Hi folks. Is there a way to customize back button behavior with
navigation-compose
? I want to make a list with multiple selection like in the GMail app. On back button press navigation-compose goes to the previous destination, but I want it to unselect all selected items. I did it with a boolean optional argument
"items?selected={selected}"
, but I think it really smells. I suppose it's better to override the default behavior of back button, but I just can't find a solution. Or is there a better approach to the problem?
i
You'd want to add your own
OnBackPressedCallback
ala https://kotlinlang.slack.com/archives/CJLTWPH7S/p1604158427082300
🙏🏼 1
We've talked about making this part of Compose here: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1604266607160300 (and that has a link to the issue you can star)
🙏🏼 1
d
Thanks a lot, Ian! The @Vinay Gaba’s message you shared lead me to his full implementation of
BackButtonHandler
that works perfectly for me. Vinay, thank you for it!
🙏🏼 1
v
@Denis The implementation in Showcase is correct - https://github.com/airbnb/Showkase/blob/9301d3dc49fa3174b813931a332d56c5565ea8ad/showkase/src/main/java/com/airbnb/android/showkase/ui/BackButtonHandler.kt#L48. I’ll update the example in Learn Jetpack Compose repo as it uses a less than ideal approach that is also being discussed in the thread that Ian pointed to.
🙏 1