I'm learning Navigating with Compose.
I found that @Composable components should be coupled with routing, but unfortunately, The way navigation-compose solves hardcoding is not so perfect. like this:
const val forYouNavigationRoute = "for_you_route"
A @Composable component is separate from its routing path, and I think it's better for them to be bound together.
I want to implement the following functionality, adding additional properties to @Composable components, using it like this:
@Composable
fun HomeScreen(navController: NavHostController) {...}
fun main(){
println(HomeScreen.label)
println(HomeScreen.route)
}
what should I do?
You need to declare your own annotation so you can easily locate target composable
Then use KSP do find this symbol then use a visitor to visit function declaration in the current file to get the name of the composable function.
Once you have got the function name (or annotation's values
routeandlabel) that is annotated with@Route, use code generator to generate object that has the properties you want as stated in