https://kotlinlang.org logo
#compose
Title
# compose
z

zoha131

03/05/2021, 4:10 PM
i am struggling to use hilt with navigation-compose library. can anyone suggest any documentation or sample? actually i didn't found any documentation.
z

zhuinden

03/05/2021, 4:14 PM
Considering you get the NavBackStackEntry as an argument of the composable { route (and it gets set as the local ViewModelStoreOwner) , it should be as simple as injecting the HiltViewModelFactory into the Activity, and then using
=
viewModel(
hiltviewmodelfactory)
Or at least I think that should theoretically work
z

zoha131

03/05/2021, 4:28 PM
@zhuinden from which package i can get
hiltviewmodelfactory
z

zhuinden

03/05/2021, 4:29 PM
seems to be
dagger.hilt.android.lifecycle.HiltViewModelFactory
z

zoha131

03/05/2021, 4:30 PM
I found this
viewModel(HiltViewModelFactory(AmbientContext.current, backStackEntry))
from release note. But unable to find any ``HiltViewModelFactory` that takes
backStackEntry
as constructor parameter.
i

Ian Lake

03/05/2021, 4:31 PM
Sounds like you've imported the wrong
HiltViewModelFactory
- don't import the
internal
one
z

zoha131

03/05/2021, 4:39 PM
then I am going to wait for the next week. lazy me 😬
6 Views