I have a Compose `ModalBottomSheetLayout` where th...
# android
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).
i
If you are using Accompanist Navigation Material, then your sheet content would be its own destination with its own set of ViewModels and you could use the normal ability to pass arguments between Navigation destinations (noting that those arguments are always available to your ViewModel via its
SavedStateHandle
)
l
That's interesting, I have to try it out. I now just pass an ItemViewModel callback setting the itemId to the MainScreen composable click listener (as both viewmodels are known by the same fragment).