allan.conda
04/07/2021, 4:05 PMcompose-navigation
.
Are there any guidelines currently about multi-module with this?
Let’s say I have two feature modules, what’s a good way to navigate screens between them without depending on each other? I’m thinking to put hoist the actual navigation into the top-level navigation (where the NavHost is), I wonder if I should be putting all those instances in there, which would be a lot for a highly-modular application.allan.conda
04/07/2021, 4:11 PMSideEffect(currentDestination)
, but I get problems of failure to navigate to the same route because the SideEffect
doesn’t run again if it’s the same route.Ian Lake
04/07/2021, 4:40 PMNavGraphBuilder.moduleNameGraph(NavController)
extension) that your main module calls when it constructs the NavHost
- that way, the logic on the internal structuring of your graph is totally contained within that module. This is the same as using an <include>
in the XML based world: https://developer.android.com/guide/navigation/navigation-nested-graphs#include
When to comes to navigating itself, the indirection through routes already decouples any compile time dependency between modules - any destination can navigate("profile/$userId")
and have that work.Ian Lake
04/07/2021, 4:43 PMNavController
).Ian Lake
04/07/2021, 4:44 PMrememberCoroutineScope
- then your button press could trigger a suspending operation, check the result, then call your navigate lambda only if needed: https://developer.android.com/jetpack/compose/kotlin#coroutinesIan Lake
04/07/2021, 4:45 PMallan.conda
04/07/2021, 6:28 PMallan.conda
04/07/2021, 6:33 PMButton(
onClick = {
coroutineScope.launch {
if (viewModel.onProfileClick()) {
navigateToUserProfile()
}
}
}
)
Ian Lake
04/07/2021, 6:34 PMIan Lake
04/07/2021, 6:41 PMLaunchedEffect
collecting on a Channel backed Flow suitable for single events: https://elizarov.medium.com/shared-flows-broadcast-channels-899b675e805c#49e3