navigation
Kotlin multi-platform application navigation library.
Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (9.6%) to scientific vocabulary
Keywords
Keywords from Contributors
Repository
Kotlin multi-platform application navigation library.
Basic Info
Statistics
- Stars: 43
- Watchers: 1
- Forks: 3
- Open Issues: 1
- Releases: 11
Topics
Metadata Files
README.md

navigation
Kotlin multi-platform application navigation library that supports Jetpack Compose.
```kotlin val navigator = rememberNavigator(initialDestination = "Greeting")
NavigationContainer(navigator) { (destination, _) -> when (destination) { "Greeting" -> Column { Text("Hello")
Button(onClick = { navigator.push("Farewell") }) {
Text("Say Goodbye")
}
}
"Farewell" -> Text("Good-bye")
else -> Text("Unexpected Destination: $destination")
}
} ```
Getting Started 🏁
The library is provided through Repsy.io. Checkout
the releases page to get the latest version.
Repository
groovy
repositories {
maven {
url = uri("https://repo.repsy.io/mvn/chrynan/public")
}
}
Dependencies
core
groovy
implementation("com.chrynan.navigation:navigation-core:VERSION")
compose
groovy
implementation("com.chrynan.navigation:navigation-compose:VERSION")
Usage 👨💻
Destinations
NavigationDestinations represent the locations within an application that a Navigator can coordinate. They can be of
any type and can contain any data that is useful to render the destination UI. A common approach is to use enums or
sealed classes to represent the different NavigationDestinations within an application.
```kotlin enum class AppDestination {
HOME,
SEARCH,
SETTINGS,
DETAILS
} ```
Contexts
A NavigationContext is a way of representing complex or nested navigation destinations. A NavigationContext defines
its initialDestination and has its own stack of NavigationDestinations associated with it within the internal
implementation of a Navigator. This allows there to be a stack of stacks of NavigationDestinations for an
application.
```kotlin
enum class MainContext(
override val initialDestination: AppDestination,
val title: String,
val icon: ImageVector
) : NavigationContext
HOME(title = "Home", icon = Icons.Default.Home, initialDestination = AppDestination.Home),
SEARCH(title = "Search", icon = Icons.Default.Search, initialDestination = AppDestination.Search),
SETTINGS(title = "Settings", icon = Icons.Default.Settings, initialDestination = AppDestination.Settings)
} ```
Navigator
A Navigator is used to navigate between navigation contexts and destinations via the
convenient push, popContext, and popDestination functions. A Navigator can be obtained via one of the
constructor functions or the remember/rememberSavable functions when using Jetpack Compose/Multiplatform Compose.
```kotlin val navigator = rememberNavigator(initialDestination = AppDestination.HOME)
BackHandler { navigator.popDestination() }
ListItem(modifier = Modifier.clickable { navigator.push(AppDestination.DETAILS) }) ```
NavigationContainer
The NavigationContainer composable provides a convenient way to listening to destination and context state changes and
recomposing its content accordingly. Just provide a Navigator instance and a content composable.
```kotlin @Composable fun App() { val navigator = rememberNavigator(initialDestination = AppDestination.HOME)
NavigationContainer(navigator = navigator) { (destination, context) ->
when (destination) {
AppDestination.HOME -> HomeScreenComposable()
AppDestination.SEARCH -> SearchScreenComposable()
AppDestination.SETTINGS -> SettingsScreenComposable()
AppDestination.DETAILS -> DetailsScreenComposable()
}
}
} ```
Transitions and animations
You have complete control over the composable functions that render the UI of the application and can use the Jetpack
Compose library's transition and animation APIs to change between the navigation context and destination UIs. For more
fine-grained control, create a custom composable replacing the NavigationContainer that handles transitions properly
for your application. Then just listen and react to the Navigator.state changes.
```kotlin
@Composable
fun
// Render UI from context and destination values and apply any transition or animation desired.
} ```
Best Practices
- Avoid passing a
Navigatorto@Composablefunctions and instead hoist the state.
```kotlin @Composable fun App() { val navigator = rememberNavigator(...)
...
MyScreen( onBackPressed = { navigator.popDestination() }, onGoToDetails = { navigator.push(AppDestination.Details(it)) } ) } ```
- Use different
Navigatorsfor deep nested navigation. This way each component can retain its own navigation hierarchy and delegate to its encapsulating component via state hoisting if it cannot handle the navigation.
```kotlin @Composable fun ParentComponent() { val parentNavigator = rememberNavigator(...)
...
ChildComponent(onBack = { parentNavigator.popDestination() })
}
@Composable fun ChildComponent( onBack: () -> Unit ) { val childNavigator = rememberNavigator(...)
BackHandler {
if (!childNavigator.canPopDestination()) {
onBack.invoke()
}
}
} ```
- Use the
rememberSavableNavigatorfunction along with serializable navigation destinations and contexts to retain the navigation state between configuration changes.
kotlin
val navigator = rememberSavableNavigator(
initialContext = MainContext.HOME,
destinationSerializer = AppDestination.serializer(),
contextSerializer = MainContext.serializer()
)
- Create the
Navigatorinstance outside of@Composablefunctions to handle navigation outside the user interface flow, such as in Activity lifecycle callbacks.
kotlin
val navigator = Navigator(initialContext = MainContext.HOME)
- Utilize side-effects in Jetpack Compose for handling navigation to non-composable UI components, such as starting new Activities or changing Fragments.
kotlin
NavigationContainer(navigator) { (destination, _) ->
when (destination) {
is AppDestination.Details -> LaunchedEffect(destination) {
context.startActivity(DetailsActivity.newIntent(context, destinatin.id))
}
}
}
- Utilize kotlinx serialization and
the serialization-parcelable library to transfer a
Navigatorbetween components.
```kotlin val navigatorSerializer = Navigator.serializer(destinationSerializer, contextSerializer)
parcelable.encodeToParcel(serializer = navigatorSerializer, value = navigator) json.encodeToString(serializer = navigatorSerializer, value = navigator) ```
Documentation 📃
More detailed documentation is available in the docs folder. The entry point to the documentation can be found here.
Security 🛡️
For security vulnerabilities, concerns, or issues, please responsibly disclose the information either by opening a public GitHub Issue or reaching out to the project owner.
Contributing ✍️
Outside contributions are welcome for this project. Please follow the code of conduct and coding conventions when contributing. If contributing code, please add thorough documents. and tests. Thank you!
Sponsorship ❤️
Support this project by becoming a sponsor of my work! And make sure to give the repository a ⭐
License ⚖️
``` Copyright 2023 chRyNaN
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ```
Owner
- Name: Christopher
- Login: chRyNaN
- Kind: user
- Location: Austin, TX
- Company: Starry
- Website: https://chrynan.codes
- Repositories: 15
- Profile: https://github.com/chRyNaN
Citation (CITATION.cff)
cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
- family-names: "Keenan"
given-names: "Christopher"
alias: "chRyNaN"
website: "https://chrynan.codes"
contact:
- family-names: "Keenan"
given-names: "Christopher"
alias: "chRyNaN"
website: "https://chrynan.codes"
title: "navigation"
type: "software"
abstract: "Kotlin multi-platform application navigation library."
license: "Apache-2.0"
keywords:
- "kotlin"
- "navigation"
- "presentation"
- "navigator"
- "navigation-architecture-component"
- "kotlin multiplatform"
- "jetpack compose"
repository-code: "https://github.com/chRyNaN/navigation"
url: "https://github.com/chRyNaN/navigation"
GitHub Events
Total
Last Year
Committers
Last synced: 7 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Chris Keenan | c****n@p****e | 71 |
| Christopher Keenan | c****n@s****m | 59 |
| Chris | c****n@p****m | 4 |
| Kévin Le Perf | c****h@g****m | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 7 months ago
Dependencies
- actions/first-interaction v1 composite
- androidx.lifecycle:lifecycle-viewmodel-compose 2.5.1 implementation
- androidx.lifecycle:lifecycle-viewmodel-ktx 2.5.1 api
- org.jetbrains.kotlinx:kotlinx-coroutines-core 1.6.4 api
- androidx.activity:activity-ktx 1.6.0 implementation
- androidx.appcompat:appcompat 1.5.1 implementation
- androidx.core:core-ktx 1.9.0 implementation
- androidx.fragment:fragment-ktx 1.5.3 implementation
- org.jetbrains.kotlin:kotlin-stdlib-common * implementation
- androidx.activity:activity-compose 1.5.1 implementation
- androidx.appcompat:appcompat 1.5.0 implementation
- androidx.compose.compiler:compiler 1.3.0 implementation
- androidx.compose.material:material-icons-extended 1.3.0-alpha03 implementation
- androidx.compose.ui:ui-tooling 1.3.0-alpha03 implementation
- androidx.core:core-ktx 1.8.0 implementation
- com.chrynan.colors:colors-compose 0.7.2 implementation
- com.chrynan.presentation:presentation-compose 0.7.1 implementation
- com.google.android.material:material 1.6.1 implementation
- actions/checkout v1 composite
- actions/setup-java v3 composite
- actions/checkout v1 composite
- actions/setup-java v3 composite
- EndBug/add-and-commit v9 composite
- actions/checkout v3 composite
- actions/setup-java v3 composite
- gradle/gradle-build-action v2 composite
- peterjgrainger/action-create-branch v2.2.0 composite
- repo-sync/pull-request v2 composite