It is up to you how you will pass down the factory to the screens. You can have a singleton object, create a
CompositionLocal
to hold the factory, or pass the factory as a parameter to every screen. Depends on your architecture.
j
John Aoussou
11/10/2021, 4:46 PM
@Csaba Kozák
It's not clear to me how you can pass the factory to the screens when using viewModel() functions, would you happen to have an example at hand?
c
Csaba Kozák
11/10/2021, 4:48 PM
Copy code
@Composable
fun HomeScreen(factory: ViewModelProvider.Factory) {
val homeViewModel: HomeViewModel = viewModel(factory = factory)
}
Of course you have to create the factory somewhere upwards.