I have migrated my Android app from jetpack compose navigation to cafe.adriel.voyager as its much easier to employ and type safe.
one draw back though with cafe.adriel.voyager is that it doesn't appear to have built in support for Android Dialogs, where compose navigation does.
with cafe.adriel.voyager not supporting Dialogs as destinations is causing me an issue when my users click the system back key.
with jetpack compose the current dialog is dismissed and the user navigates back to the previous destination as expected.
with cafe.adriel.voyager however i to detect the key event as shown below and pop the the current destination
if (keyEvent.nativeKeyEvent.keyCode == KeyEvent.KEYCODE_BACK) {
if (keyEvent.nativeKeyEvent.action == KeyEvent.ACTION_DOWN) navigator.pop()
true
} else false
in addition i also have to add the following code in the hosting dialogfragment to stop the back key propagating upwards and exiting the previous destination as well
@Suppress("ControlFlowWithEmptyBody")
override fun onResume() {
super.onResume()
requireDialog().setOnKeyListener { _, keyCode, event ->
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (event.action == KeyEvent.ACTION_UP) {
// INTENTIONALLY LEFT BLANK
}
}
false
}
}
override fun onDestroyView() {
requireDialog().setOnKeyListener(null)
super.onDestroyView()
}
is there a better approach to using cafe.adriel.voyager as my applications navigator?