Seb Jachec
05/16/2022, 11:58 AMclass SharedViewModel(val id: String?)
val sharedModule = module {
factoryOf(::SharedViewModel)
}
Android:
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()) }) }
}
arnaud.giuliani
05/17/2022, 7:04 AMviewModel { params -> AndroidViewModel(params.getOrNull())) }
arnaud.giuliani
05/17/2022, 7:05 AMviewModelOf(::AndroidViewModel)
form should works, but perhaps an issue on thisSeb Jachec
05/17/2022, 9:58 AMviewModel { params -> AndroidViewModel(get { params }) }
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.arnaud.giuliani
05/17/2022, 10:01 AM