raamcosta / compose-destinations

Annotation processing library for type-safe Jetpack Compose navigation with no boilerplate.
https://composedestinations.rafaelcosta.xyz
Apache License 2.0
3.2k stars 132 forks source link

NestedGraph destinations not in parent NavGraphSpec.allDestinations #611

Closed s0nance closed 4 months ago

s0nance commented 5 months ago

Hello!

I encountered an issue where calling my current NavGraph .allDestinations extension is not returning the nested nav graphs destinations.

Here is my generated tree:

 * * πŸ—ΊοΈ[MenuNavGraph]
 * * βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™β†³πŸ—ΊοΈπŸ[Page1NavGraph]
 * * βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™β†³πŸ“πŸ[Page1Screen]
 * * βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™β†³πŸ—ΊοΈ[SettingsNavGraph]
 * * βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™β†³πŸ“πŸ[SettingsScreen]
 * * βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™β†³πŸ—ΊοΈ[FromSettingsLoginGraph]
 * * βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™β†³πŸ“πŸ[LoginScreen]
 * * βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™β†³πŸ—ΊοΈ[FromSettingsRegisterGraph]
 * * βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™β†³πŸ“πŸ[RegisterScreen]
 * * βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™β†³πŸ—ΊοΈ[Page2NavGraph]
 * * βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™β†³πŸ“πŸ[Page2Route]
 * * βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™β†³πŸ“[Page2-1Route]
 * * βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™βˆ™β†³πŸ“[Page2-3Route]
 *

I expect the extension to return, for FromSettingsLoginGraph, the given destinations: [FromSettingsLoginLoginScreenDestination, FromSettingsRegisterRegisterScreenDestination], but it seems to only return FromSettingsLoginLoginScreenDestination.

Is this an expected behavior ?

I used a small function to check if my current destination is well a part of the nested navigation:

appCurrentDestinationState?.route?.let {
   topLevelDestination.graph.findDestination(it) // here topLevelDestination represents FromSettingsLoginGraph
} != null

and it returns true when I navigate to (so when appCurrentDestinationState route equals:) FromSettingsRegisterRegisterScreenDestination. So it seems it is indeed a part of the nested graphs!

By looking at your code, inside the SpecExtension.kt file, it seems you are recursively returning all destinations, even those from nestedNavGraphs, so I guess it is a bug?

I'm looking forward to hear your advice on this! Thank you

raamcosta commented 5 months ago

What Compose Destinations version are you using?

s0nance commented 5 months ago

Compose Destinations v2.0.0-beta01 Jetpack Compose version 1.6.5

raamcosta commented 4 months ago

Yes, you are right. Will be fixed on next versions. Thanks for reporting!

raamcosta commented 4 months ago

Included on beta07 building now. Thank you once again! πŸ™

s0nance commented 4 months ago

No problem, it's been a pleasure!

Thanks for your work.