https://kotlinlang.org logo
#compose
Title
# compose
l

Lukasz Kalnik

08/05/2022, 12:49 PM
I have a
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).
m

myanmarking

08/05/2022, 2:01 PM
create an Item with itemId, use it as lazyColumn item id and also, use a lambda with a callback with that same id with the click, and pass it to the details viewmodel
l

Lukasz Kalnik

08/05/2022, 2:03 PM
Yes, the passing of the callback to the details viewmodel was something I was missing. It is actually quite easy, as both viewmodels are known by the same host (fragment in my case), so I can pass their callbacks to the composable click listeners. Thank you for the hint!
9 Views