https://github.com/lukwol/navigation
Simple navigation in Compose Multiplatform apps
https://github.com/lukwol/navigation
android compose desktop ios kotlin multiplatform navigation web
Last synced: about 2 months ago
JSON representation
Simple navigation in Compose Multiplatform apps
- Host: GitHub
- URL: https://github.com/lukwol/navigation
- Owner: lukwol
- License: mit
- Archived: true
- Created: 2022-11-06T10:33:22.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-15T21:17:42.000Z (about 1 year ago)
- Last Synced: 2024-08-01T19:55:28.459Z (10 months ago)
- Topics: android, compose, desktop, ios, kotlin, multiplatform, navigation, web
- Language: Kotlin
- Homepage: https://lukwol.github.io/navigation
- Size: 774 KB
- Stars: 12
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - lukwol/navigation - Simple navigation in Compose Multiplatform apps (Kotlin)
README
# navigation
[](https://central.sonatype.com/namespace/io.github.lukwol)
[](https://github.com/lukwol/navigation/actions/workflows/check.yml)Tiny library for easy navigation
in [Compose Multiplatform](https://github.com/JetBrains/compose-jb/)
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
| navigation | compose-multiplatform |
|:----------:|:---------------------:|
| 1.4.0 | 1.6.1 |
| 1.3.2 | 1.5.12 |
| 1.3.1 | 1.5.11 |
| 1.3.0 | 1.5.10 |
| 1.2.0 | 1.5.3 |
| 1.1.0 | 1.5.2 |
| 1.0.0 | 1.5.1 |## Installation
Add `mavenCentral` and `google` repositories:
```kotlin
repositories {
mavenCentral()
google()
}
```Declare dependencies in `build.gradle.kts`:
```kotlin
dependencies {
// Screens navigation - multiplatform
implementation("io.github.lukwol:navigation-screens:1.4.0")
// Screens navigation with ViewModel support - multiplatform
implementation("io.github.lukwol:navigation-screens-viewmodel:1.4.0")
// Windows navigation - desktop application only
implementation("io.github.lukwol:navigation-windows:1.4.0")
}
```## Usage
Bootstrap new project with handy [`app-template`](https://github.com/lukwol/app-template/).
### Build screens navigation
Basic screens navigation:
```kotlin
ScreensNavigation(
startRoute = AppRoutes.FirstScreenRoute,
) {
screen(AppRoutes.FirstScreenRoute) {
FirstScreen()
}screen(AppRoutes.SecondScreenRoute) { args: String? ->
SecondScreen(args)
}
}
```Screens navigation with `ViewModel` and custom animations:
```kotlin
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)
```kotlin
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
```kotlin
// Obtain LocalScreensController in your view
val screensController = LocalScreensController.current// Push screen
screensController.push(AppRoutes.SecondScreenRoute)// Optionally pass arguments if needed
screensController.push(AppRoutes.SecondScreenRoute, SomeArguments)// Pop screen to navigate back
screensController.pop()// Optionally pass route, up to which screens should be dismissed
screensController.pop(AppRoutes.FirstScreenRoute)
```### Navigate to window (desktop)
```kotlin
// Obtain LocalWindowController in your view
val windowsController = LocalWindowController.current// Open window
windowsController.open(AppRoutes.SecondWindowRoute)// Optionally pass arguments if needed
windowsController.open(AppRoutes.SecondWindowRoute, SomeArguments)// Close window
windowsController.close(AppRoutes.SecondWindowRoute)
```## Documentation
API Reference is available at https://lukwol.github.io/navigation/
## Licensing
Project is available under [MIT](https://github.com/lukwol/navigation/blob/main/LICENSE) License.