https://kotlinlang.org logo
#android-architecture
Title
# android-architecture
l

Lukasz Kalnik

08/05/2022, 12:56 PM
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

K Merle

08/07/2022, 7:56 PM
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

Lukasz Kalnik

08/07/2022, 8:00 PM
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

Arun Joseph

08/10/2022, 12:43 PM
We use nested
NavHost
for such bottom panel, so I can get
viewModel
scoped to bottom panel content.
11 Views