Hi folks. Can anyone offer advice on best practice for constructing nested navigation in a use case like this? I have an activity which provides behaviour based on some user-selected plugins. So the user can navigate to a “plugin screen”, at which point the UI content is provided by a plugin. I would like to define some nested navigation within the plugin, and I’m trying to figure out the best way to do this. My idea so far is to do something roughly like this:
@Composable
fun MainNavHost(
navController: NavHostController,
plugin: Plugin,
) {
NavHost(...) {
// Define regular navigation within the activity
composable(...) {
...
}
// Call this here to define nested navigation for plugin(s)
plugin.navGraph(navController)
}
}
interface Plugin {
fun NavGraphBuilder.navGraph(navController: NavHostController)
...
}
This seems fine to me, though I don’t like passing
navController
down to the plugin. But it isn’t obvious to me how to avoid this, since there will be navigation to do within the plugin.
But… does this seem sensible? Any risks stand out to you that I may not have considered? Any feedback is appreciated, thanks!