The reason that Google recommends `ViewModel` for ...
# squarelibraries
k
The reason that Google recommends
ViewModel
for compose likely hinges on the interaction of the hilt library,
ViewModel
, and compose navigation. They're so closely intertwined that some use cases are nice to use with that. If you try to do anything out of the norm (see: assisted injection) you get nothing but pain
c
FWIW, I think assisted injection now that its built into dagger/hilt actually works well with all those libs
k
Last I heard this issue hasn't been resolved yet. https://github.com/google/dagger/issues/2287
c
Oooh. I def just used it and it worked. lol. I wonder if I need to leave a comment similar to this one i just left last week 😂 https://github.com/google/dagger/issues/1908#issuecomment-1424328026
Okay, that thread actually has a tonnnn more convo going on in it. almost to the point where its hard to follow what is supported currently and what is not supported currently. dagger seems to have "assisted injection" though and the last time i used AI it was for a use case, not an AAC VM, so maybe that actually doesn't work. https://dagger.dev/dev-guide/assisted-injection.html
k
@AssistedInject
does not work for classes annotated with
@HiltViewModel
currently and fails with a compiler error.
The thread is definitely difficult to follow. I want to rip hilt out of our codebase so bad.
c
Ah gotcha. Then yeah I misremembered our impl. We currently use saved state handle with compose nav in order to get the typical destination based args.