raamcosta / compose-destinations

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

Define Custom Properties for all destinations of a Graph #425

Open hscissors opened 1 year ago

hscissors commented 1 year ago

Is there any way define custom properties on a graph, and then check them as part of the NavController.currentDestination?

For example:

@RootNavGraph(start = true)
@NavGraph
annotation class UnauthenticatedNavGraph(
    val start: Boolean = false,
    val showBottomNav: Boolean = false //<---- This custom property 
)

and then something like:

val showBottomNav =  if(navController.currentDestination.parent == NavGraphs.UnauthenticatedNavGraph) navController.currentDestination.parent.showBottomNav

Edit: Or if there is a way to do the same for the @Destination annotation, which probably would be better

raamcosta commented 1 year ago

No way to do this, no. Could be a fun idea, although the property would be part of all destinations of the graph and not really of the NavGraph itself, since when using this annotation, some destination could override and pass true as showBottomNav.