dave08
09/24/2024, 4:03 PMtoRoute()
multiple times and catch each one until the right one is found, or maybe make them inherit from a base sealed interface and use toRoute()
on that (is that supported)?Joseph Hawkes-Cates
09/24/2024, 9:21 PMtoRoute()
with a sealed interface type when passing in the concrete implementation for the route doesn’t work out of the box. You can maybe get it to work by providing your own NavType
impl. I ended up refactoring these screens to actually be a single route by moving them out into their own nav graph so they can be routed to from multiple other nav graphs.Stylianos Gakis
09/25/2024, 9:04 AMdave08
09/25/2024, 9:06 AMStylianos Gakis
09/25/2024, 9:11 AMinternal class FooViewModel(
private val someInteraction: SomeUseCase,
private val savedStateHandle: SavedStateHandle,
) : MoleculeViewModel<FooEvent, FooUiState>(
FooUiState.Loading,
FooPresenter(someInput = savedStateHandle.toRoute<>().someInput, someInteraction = someInteraction),
)
and the presenter does all the work.
That's what I'd do here, so each screen has one VM and grabs its own SavedStateHandle, but you share the logic somewhere else.dave08
09/25/2024, 9:16 AMStylianos Gakis
09/25/2024, 9:20 AM