Open tsenggordon opened 2 years ago
Hey @tsenggordon. My guess is that currently that intermediate fragment is an AuthAwareFragment
. What you'll need to do is have that intermediate fragment be either an AuthRequiredFragment
or an AuthOptionalFragment
that will create a new scope under it:
Let me know if this works.
@rodgavila, sorry I missed one important detail, is that the parent Activity is not a kaiken supported activity (It is an AppCompatActivity), is it still possible the make the change you suggested? If not, is there a way to do user scoping without having the parent activity being KaikenActivitiy?
The parent activity will need to be a Kaiken activity, no way around that. Is there an issue preventing you from ch as find that to be a Kaiken activity? It should be a very minimal change. And ideally all Activities should eventually be Kaiken activities.
Hey @rodgavila and @tsenggordon - The parent activity is our main activity. It implements AuthOptionalActivity
. I changed the scoping of the intermediate fragments to implement AuthRequiredNavHostFragment
and AuthRequiredFragment
. However I still get error that Fragment does not implement InjectorHolder and neither its parent activity. Thoughts?
Hi @matt-ramotar. Could further elaborate on the class structure? Who extends from what? Just to make sure we're on the same page.
Is the AuthRequiredFragment contained inside the AuthRequiredNavHostFragment? That would seem off. Be cause the contained fragment could simply inherit it's auth required scope from the parent AuthRequiredNavHostFragment. Changing it to an AuthAwareFragment would help.
Yeah of course. Overview below. Thanks for taking a look. Really appreciate it
Our IAP flow can be launched from MainActivity
and IapActivity
:
IapActivity
implements AuthRequiredActivity
and InjectorHolder<IapComponent>
and has iap_nav_graph
MainActivity
implements AuthOptionalActivity
When IAP flow is launched from MainActivity
:
ParentFragment
ParentFragment
implements AuthRequiredFragment
and InjectorHolder<IapComponent>
ParentFragment
embeds iap_nav_graph
in AuthAwareNavHostFragment
GrandchildFragment
implements AuthAwareFragment
GrandchildFragment
invokes inject()
in onAttach
Exception:
com.dropbox.kaiken.runtime.InjectorNotFoundException
The main activity that hosts the fragments needs to be an InjectorHolder of the component otherwise, it won't find the component.
I have a feature that utilize Android navigation. The activity implements the
getInjectorFactory()
to provide the component for all the fragments in the nav_graph. However, we have another project that requires the logic to be condense in a Fragment instead of Activity, and the fragment owns the nav_graph. Under current implementation,Fragment.findInjector()
only checks the fragment itself, and its parent activity, but not the fragment chain. I would like to know if there is an workaround to have the OWNER fragment implementsgetInjectorFactory()
like the activity does, instead of having to implementInjectorHolder
for every single fragment in the graph (It is also inefficient to do so, components are re-created, and if we have to pass fields in the component factory, it is very hard to pass those arguments.) @rodgavila do you know any workaround?