Colton Idle
01/19/2022, 3:32 PMbottomSheet(route = Screen.NumberPickerBottomSheet.route) {
NumberPickerBottomSheet()
}
In the bottom sheet when the "Save" button is hit, I want to update the number value to the screen/VM that started the bottomSheet. Since it was a navigation event that started the bottom sheet, I can't pass a lambda of like onNumUpdateEvent
. What's the best way to go about this? The only other thing that comes to mind is for the screen/VM to implement some interface or something? Or maybe I just save the state in some Activity level VM? Edit: Or another option is to use the navController in the bottomsheet and use that to get the previous entry and get the VM/cast to the VM and update it that way?Desmond Teo
01/19/2022, 3:58 PMNumberPickerBottomSheet(
onPickNumber = { value ->
navController.previousBackStackEntry?.savedStateHandle?.set(key, value)
}
)
navBackStackEntry.savedStateHandle
using the same key the picker usedColton Idle
01/19/2022, 4:51 PMArjun Achatz
01/19/2022, 7:13 PMnavController.previousBackStackEntry
seems a lot like starting an activity/fragment for result, which I've never been a fan of from a state mgmt prospectiveColton Idle
01/19/2022, 8:48 PMDesmond Teo
01/20/2022, 2:31 AMOh hm. Interesting. Do those values only get "transfered" once the bottom sheet collapses/goes away though? example: In the activity/fragment world with extras you only got the "extra" once the activity/fragment was closed.You can see the values immediately, because the previous destination is still active.
Colton Idle
01/20/2022, 3:49 AMMichal Klimczak
01/21/2022, 1:34 PM