I am trying to add confirmation dialog that has a ...
# compose
k
I am trying to add confirmation dialog that has a callback. I've noticed that NavHost has a feature to add dialog to it, but with callback it seems messy as I'd have to return callback to the nested composable in different screen. Any good examples of confirmation dialog with compose?
f
You can pass data back using the backstack, this shows how to pass some info from one screen to the previous, you can use this principle if you don't want callbacks https://medium.com/p/2649459c5f98
k
Are there any cons of showing plain composable AlertDialog with a callback and just use condition to show or hide it?
f
Not that I can think of, though I wonder how that's going to work if you have process death
a
The dialog composables already work as you describe, put an
if
around one and you can manage whether it's present or not
🙌 1
i
Yep, we actually specifically call out that things that have the shape of a AlertDialog (like most confirmation dialogs) should just use
Dialog
directly and not make a whole separate navigation destination: https://developer.android.com/reference/kotlin/androidx/navigation/compose/package-summary#(androidx.navigation.NavGra[…]roperties,kotlin.Function1)
🙌 1