arnaud.giuliani
08/21/2020, 1:31 PMMohamed Elfiky
08/21/2020, 2:17 PMarnaud.giuliani
08/21/2020, 2:42 PMMohamed Elfiky
08/21/2020, 2:45 PMzsperske
08/23/2020, 5:29 PMaipok
08/26/2020, 2:42 PMalpha
it is compared to 2.1.6?arnaud.giuliani
08/26/2020, 3:48 PMarnaud.giuliani
08/26/2020, 3:48 PMarnaud.giuliani
08/26/2020, 3:48 PMarnaud.giuliani
08/26/2020, 3:48 PMaipok
08/27/2020, 6:06 AMparametersOf()
must be cast to Any
and could not be nullable. Type mismatch: inferred type is String? but Any was expected
Also could you tell me if I have updated a ViewModel instantiation correctly?
I have replaced the old code
viewModel = lifecycleScope.getViewModel<FormsViewModel>(this) {
parametersOf(
intent?.getBooleanExtra(ProcessHelper.IntentParamShouldReset, false) ?: false,
intent?.getStringExtra("processName")
)
}
to
val viewModel = scope.getViewModel<FormsViewModel>(null, emptyState(),
{ ViewModelOwner.from(viewModelStore) }, parameters = {
parametersOf(
intent?.getBooleanExtra(ProcessHelper.IntentParamShouldReset, false)
?: false,
intent?.getStringExtra("processName") as Any,
)
}
)
Old implementation looks much more cleaner than the current one and also there are many viewModel(...)
methods, that I found confusing in terms of which I should use. If you could provide some suggestion or samples how it should be used, that will be very much appreciated.
Will describe what I want to achieve in case you might know the easier way 😄
I have an activity that initiates view model and all the fragments and child fragments inside that activity are able to access this view model if needed via Activity. And during activity lifecycle the same instance of ViewModel is delivered to fragments via `getSharedViewModel` call.
In 2.1.6 I done this via activity `lifecycle`
module definition looks like this:
scope(named<MyActivity>()) {
viewModel { (intent: Intent?) -> MyViewModel(get(), get(), intent) }
}
arnaud.giuliani
08/27/2020, 7:31 AMaipok
08/27/2020, 8:01 AM