MaxUt
08/05/2021, 7:43 AMMaxUt
08/05/2021, 7:45 AMclass SearchViewManager @Inject constructor(
val catalogManager: CatalogManager,
private val _widgetManager: WidgetsManager
) {
...
}
@Composable
fun SearchScreen() {
val searchViewManager: SearchViewManager = SearchViewManager()
}
However, it seems like I have to pass the parameters.Colton Idle
08/05/2021, 1:40 PMhiltViewModel()
See: https://developer.android.com/jetpack/compose/libraries#hiltMaxUt
08/05/2021, 2:14 PMColton Idle
08/05/2021, 2:18 PMMaxUt
08/05/2021, 2:19 PMTgo1014
08/05/2021, 2:22 PMColton Idle
08/05/2021, 2:24 PMColumn{
ScreenA
ScreenA
}
then whatever change you make in the top screenA, should also be shown in the bottom screenA.MaxUt
08/05/2021, 2:25 PMColton Idle
08/05/2021, 2:26 PMTgo1014
08/05/2021, 2:29 PMMaxUt
08/05/2021, 2:33 PMTgo1014
08/05/2021, 2:35 PMMaxUt
08/05/2021, 2:35 PMColton Idle
08/05/2021, 2:36 PMknthmn
08/06/2021, 7:29 AMkey in hiltViewModel() (or viewModel() ) to get several viewmodels in the same scope.
val a = viewModel<FooVM>(key = "1")
val b = viewModel<FooVM>(key = "2")
println(a === b) // falseTgo1014
08/06/2021, 7:58 AMknthmn
08/06/2021, 8:09 AM@HiltViewModel from com.google.dagger:hilt-android
https://developer.android.com/training/dependency-injection/hilt-jetpack#viewmodels
edit: I checked hiltViewModel() doesn't provide a key parameter, however you can copy the function and add the key parameter that is passed to viewModel().Tgo1014
08/06/2021, 8:12 AMhiltViewModel<T>() which, afaik, doesnât have a âkeyâ parameters to define a scopeknthmn
08/06/2021, 8:16 AMhiltViewModel() does is hook in the factory for creating the vm, i think it is safe to add a key parameter to it.Tgo1014
08/06/2021, 8:18 AMTgo1014
08/06/2021, 8:24 AMjava.lang.IllegalArgumentException: SavedStateProvider with the given key is already registeredknthmn
08/06/2021, 8:27 AM@ViewModelInject (which I used a few months ago)