I've got an interesting case. I don't know how to ...
# compose-android
c
I've got an interesting case. I don't know how to inject one of my classes (using dagger/hilt) into my composable. I'm using AAC VM + hilt + navigation etc, BUT the wrench in the whole thing is that outside of my root NavHost, I have a "global dialog" for showing things like a force update prompt, etc. So now I basically have this really simple scenario of Box { NavHost GlobalDialog } but my GlobalDialog needs access to a class that I typically inject into my screens. Thoughts?
f
You could have a ViewModel at the activity level that you pass to your dialog, and inject into the viewmodel whatever you need in the dialog, then expose the data to the dialog via a state class. Alternatively you could create a state holder that contains whatever you need to inject, which is injected at the activity and then used to instantiate the state holder, which is passed to the dialog.
s
Just inject it at your activity directly? And pass it into the composable that needs it.
c
Injecting into my activity directly. Was curious if maybe I was missing something basic... but yeah the basic activity inject worked as expected. Thanks all for saving my sanity
d
Are you using the
NavGraphBuilder.dialog()
function?
It sets up a dialog as a navigation destination in the graph.