Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Named dependencies? #232

Open
kassim opened this issue Aug 31, 2022 · 2 comments
Open

Named dependencies? #232

kassim opened this issue Aug 31, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@kassim
Copy link

kassim commented Aug 31, 2022

It seems as though we're only able to provide one dependency of each type, would it perhaps be possible to provide them as named dependencies so we can provide multiple dependencies of the same type? Perhaps using the @Named(" ") annotation

My reason:
I have my root composeable with a DestinationsNavHost which can navigate to a Home composeable screen which holds a DestinationsNavHost controlled by a bottom bar, from that bar we can navigate to a Profile screen, and then within the Profile screen we want an action to navigate to a new screen that should not be within the Home screen's DestinationsNavHost, but within the root's.

At the moment I've made a wrapping class class ParentDestinationsNavigator(val nav: DestinationsNavigator), made my Home screen's
DestinationsNavHost(.. dependenciesContainerBuilder = { dependency(ParentDestinationsNavigator(destinationsNavigator))}) and my Profile screen constructor is class Profile(nav: ParentDestinationsNavigator) but would have rather had something like class Profile(@Named("root") nav: DestinationsNavigator) so that the correct DestinationsNavigator is always addressed

perhaps I'm missing a more obvious solution to my requirement

@raamcosta
Copy link
Owner

Hey @kassim 👋

Yeah this does make sense. I have had a similar idea in my mind for some time. I'm thinking about this specific case of a parent navigator and maybe there is a simpler way to do it.
Anyway, I'll keep this open as a good enhancement :)

@raamcosta raamcosta added the enhancement New feature or request label Aug 31, 2022
@HarryTylenol
Copy link

You can try it with interface delegation.
This is not a answer, but just some small tweak before named dependency feature get released.

class ParentDestinationsNavigator(delegate: DestinationsNavigator) : DestinationsNavigator by delegate

..

@SubNavGraph
@Destination
@Composable
fun SubScreen(
    parentNavigator : ParentDestinationsNavigator,
    navigator: DestinationsNavigator
) {
   ..
   // you can use navigate function directly
   parentNavigator.navigate(OtherScreenDestination)

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants