navigation

Tiny library for easy navigation
in Compose Multiplatform
applications.
Provides:
- Screens navigation - multiplatform
- Optional
ViewModel with work cancellation support - multiplatform
- Windows navigation - desktop only
Versions
For each version of navigation specific version of Compose Multiplatform is required
Installation
Add mavenCentral and google repositories:
repositories {
mavenCentral()
google()
}
Declare dependencies in build.gradle.kts:
dependencies {
implementation("io.github.lukwol:navigation-screens:1.4.0")
implementation("io.github.lukwol:navigation-screens-viewmodel:1.4.0")
implementation("io.github.lukwol:navigation-windows:1.4.0")
}
Usage
Bootstrap new project with handy app-template.
Build screens navigation
Basic screens navigation:
ScreensNavigation(
startRoute = AppRoutes.FirstScreenRoute,
) {
screen(AppRoutes.FirstScreenRoute) {
FirstScreen()
}
screen(AppRoutes.SecondScreenRoute) { args: String? ->
SecondScreen(args)
}
}
Screens navigation with ViewModel and custom animations:
ScreensNavigation(
startRoute = AppRoutes.FirstScreenRoute,
enterTransition = {
slideIntoContainer(AnimatedContentTransitionScope.SlideDirection.Left)
},
exitTransition = {
slideOutOfContainer(AnimatedContentTransitionScope.SlideDirection.Left)
},
popEnterTransition = {
slideIntoContainer(AnimatedContentTransitionScope.SlideDirection.Right)
},
popExitTransition = {
slideOutOfContainer(AnimatedContentTransitionScope.SlideDirection.Right)
},
) {
screen(
route = AppRoutes.FirstScreenRoute,
viewModelFactory = {
FirstScreenViewModel()
}
) { viewModel ->
FirstScreen(viewModel)
}
screen(
route = AppRoutes.SecondScreenRoute,
viewModelWithArgs = { args: SomeArgs? ->
SecondScreenViewModel(args)
}
) { viewModel ->
SecondScreen(viewModel)
}
}
Build windows navigation if needed (desktop)
WindowsNavigation(
startRoute = AppRoutes.FirstWindowRoute
) {
window(
route = AppRoutes.FirstWindowRoute,
title = "First Window"
) {
ScreensNavigation(
startRoute = AppRoutes.FirstScreenRoute
) {
}
}
window(
route = AppRoutes.SecondWindowRoute,
title = "Second Window"
) {
ScreensNavigation(
startRoute = AppRoutes.SecondScreenRoute
) {
}
}
}
Navigate to screen
val screensController = LocalScreensController.current
screensController.push(AppRoutes.SecondScreenRoute)
screensController.push(AppRoutes.SecondScreenRoute, SomeArguments)
screensController.pop()
screensController.pop(AppRoutes.FirstScreenRoute)
Navigate to window (desktop)
val windowsController = LocalWindowController.current
windowsController.open(AppRoutes.SecondWindowRoute)
windowsController.open(AppRoutes.SecondWindowRoute, SomeArguments)
windowsController.close(AppRoutes.SecondWindowRoute)
Documentation
API Reference is available at https://lukwol.github.io/navigation/
Licensing
Project is available under MIT License.