Hi, I’m using Koin 3.2.0 in a KMM project, targeting Android (Jetpack Compose) and iOS. I’m trying to pass a parameter from Jetpack Compose, through an Android view model, into a common/shared view model that the Android view model depends on. Could anyone point me in the right direction?
Common/shared:
Copy code
class SharedViewModel(val id: String?)
val sharedModule = module {
factoryOf(::SharedViewModel)
}
Android:
Copy code
class AndroidViewModel(val sharedViewModel: SharedViewModel)
@Composable
fun MyScreen(
id: String?
) {
val viewModel = getViewModel<AndroidViewModel>(parameters = { parametersOf(id) })
}
val androidModule = module {
// Neither of these work here:
// viewModelOf(::AndroidViewModel)
// viewModel { params -> AndroidViewModel(get { parametersOf(params.getOrNull()) }) }
}
in the end. I over-simplified the code that I posted here, which probably wasn’t helpful to anyone reading 😅 but there was a different issue preventing my 2nd commented line from working.