I have a Compose `ModalBottomSheetLayout` where th...
# android-architecture
l
I have a Compose
ModalBottomSheetLayout
where the contents is the main screen with a list of items, and the
sheetContent
are item details (with different settings). As the item details are quite complex, and don't influence the main screen, I would like to have them in a separate ViewModel. How can I pass the
itemId
from the
MainScreenViewModel
to the
ItemDetailsViewModel
. I don't really fancy creating a shared ViewModel just to pass one value (which is anyway only temporary, as the
ItemDetailsViewModel
will store
itemId
as well to get the item data).
k
Can you have a use-case with a hot-stream variable that would hold currently selected item, and pass that use-case to a
list
and
details
ViewModels?
l
Thanks for the suggestion. In the end I went with a callback in details ViewModel to set the current item.
But someone also advised the Accompanist library, which turns bottom sheet layout into compose navigation destination. This would be the most logical solution (after all, the bottom sheet might call another bottom sheet and you might want to have a back stack).
a
We use nested
NavHost
for such bottom panel, so I can get
viewModel
scoped to bottom panel content.