A lightweight, cross-platform Coordinator library, written in pure Kotlin. Can easily support other navigation libraries or a custom navigation logic.
A convenient and powerful coordinator pattern library designed for Navigation Compose library.
-
KCoordinatorAction: Coordinator Action: Actions that can be handled by navigation flow logic in the Coordinator. For example, start the authentication flow, show home screen, go to back screen or another screen of navigation flow.
interface KCoordinatorAction
-
KCoordinator: Core Coordinator: The Coordinator core interface in pure Kotlin. Each coordinator can set up navigation and trigger and handle actions.
interface KCoordinator<T: KCoordinatorAction> {
fun trigger(action: KCoordinatorAction) {
}
fun handle(action: T)
}
-
ComposeKCoordinator: Navigation Compose Coordinator: The Compose Coordinator interface. Each Compose Coordinator can set up navigation, trigger and handle actions and setting up navigation compose.
interface ComposeKCoordinator<T: KCoordinatorAction> : KCoordinator<T> {
fun trigger(action: KCoordinatorAction) {
}
fun handle(action: T)
fun setupNavigation(
navGraphBuilder: NavGraphBuilder,
navHostController: NavHostController
)
}
-
RootComposeKCoordinator: Root Compose Coordinator: Root Compose Coordinator interface. It initializes the navigation graph and handles global navigation actions and flows.
interface ComposeKCoordinator<T: KCoordinatorAction> : KCoordinator<T> {
fun handle(action: T)
fun setupNavigation(
initialAction: Action,
navGraphBuilder: NavGraphBuilder,
navHostController: NavHostController
)
@Composable
fun start(
startDestination: Any,
initialAction: T
) {
val navHostController = rememberNavController()
NavHost(
startDestination = startDestination,
navController = navHostController
) {
setupNavigation(
initialAction,
this,
navHostController
)
}
}
}
This repository showcases a flexible navigation approach for Jetpack Compose applications by implementing the Coordinator pattern. This pattern simplifies the management of complex navigation flows and screen transitions, offering a well-structured way to handle navigation across different screens in an Android ou Multiplatorm Compose apps.
-
AppCoordinator: Manages the app's overall navigation flow and initializes either the authentication flow or the main flow based on the current state.
-
AuthCoordinator: Manages the authentication flow, including login and forget password screens.
-
HomeCoordinator: Manages the main flow, including the home screen and settings screens.
By decoupling navigation logic from UI components, it simplifies the management of complex navigation flows.
The Coordinator pattern offers a scalable and flexible architecture benefits for large applications that involve multiple navigation flows and nested navigation structures.