Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lachlanmckee/hilt-compose-navigation-factory
https://github.com/lachlanmckee/hilt-compose-navigation-factory
Last synced: about 12 hours ago
JSON representation
- Host: GitHub
- URL: https://github.com/lachlanmckee/hilt-compose-navigation-factory
- Owner: LachlanMcKee
- License: apache-2.0
- Created: 2021-04-06T22:21:15.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-05-14T19:31:51.000Z (6 months ago)
- Last Synced: 2024-05-15T16:01:58.628Z (6 months ago)
- Language: Kotlin
- Size: 390 KB
- Stars: 25
- Watchers: 3
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Hilt Compose Navigation Factory
A set of tools to move the responsibility of building a Compose navigation graph to factories that can be defined within other modules.
By using this library in conjunction with Dagger Hilt these factories are combined into a `Set` which can then be used to construct the navigation graph via the `hiltNavGraphNavigationFactories` extension function.
## How to use
You construct any number of `ComposeNavigationFactory` implementations in any modules.
```kotlin
// This annotation allows the annotation processor to add the ComposeNavigationFactory implementation to the dagger graph.
@HiltComposeNavigationFactory
internal class ExampleComposeNavigationFactory @Inject constructor() : ComposeNavigationFactory {
override fun create(builder: NavGraphBuilder, navHostController: NavHostController) {
builder.viewModelComposable(
route = "example",
content = {
ExampleComposable(
viewModel = this,
navHostController = navHostController
)
}
)
}
}@Composable
internal fun ExampleComposable(viewModel: ExampleViewModel, navHostController: NavHostController) {
}@HiltViewModel
internal class ExampleViewModel @Inject constructor() : ViewModel() {
}
```Within the Composable that hosts the navigation graph you can access the `Set` of factories.
```kotlin
@Composable
fun JetpackNavigationHiltApp() {
val navController = rememberNavController()
val context = LocalContext.current// The start destination would still need to be known at this point.
NavHost(navController, startDestination = "example") {
hiltNavGraphNavigationFactories(context).addNavigation(this, navController)
}
}
```To see this in practice, please take a look at the [sample](sample) directory.
## Download
This library is available on Maven, you can add it to your project using the following gradle dependencies:```gradle
implementation 'net.lachlanmckee:hilt-compose-navigation-factory:1.3.0'
annotationProcessor 'net.lachlanmckee:hilt-compose-navigation-factory-compiler:1.3.0'
```