Skip to content

Commit

Permalink
Merge pull request #4 from ScottPierce/scott/Voyager
Browse files Browse the repository at this point in the history
Support Voyager
  • Loading branch information
ScottPierce authored Jul 17, 2024
2 parents 866a97f + ffb3d8b commit 6864795
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 11 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ A multiplatform Dependency Injection library.
implementation("dev.scottpierce:kinject-core:<latest version here>")
```

| Artifact | Description |
|----------------------------|------------------------------------------------------------------------------------------------------------------------------------------------|
| kinject-core | Provides core DI functionality. |
| kinject-android | Provides helper methods for working with `ObjectGraph`s embedded in `Context`s, and helper classes for embedding `ObjectGraph`s in `Contexts`. |
| kinject-android-appcompat | Provides `KinjectAppCompatActivity`. |
| kinject-android-compose | Provides `KinjectComponentActivity`. |
| kinject-compose | Provides the ability to provide an ObjectGraph in a Compose hierarchy. |
| kinject-compose-viewmodel | Provides the ability to get a ViewModel in a compose hierarchy. |
| kinject-coroutines | Provides a `KinjectCoroutineContextElement`, to easily allow passing an `ObjectGraph` via a `CoroutineContext`. |
| kinject-viewmodel | Provides the ability to declare a view model dependency, and a factory to create it. |
| Artifact | Description |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------|
| kinject-core | Provides core DI functionality. |
| kinject-android | Provides helper methods for working with `ObjectGraph`s embedded in `Context`s, and helper classes for embedding `ObjectGraph`s in `Contexts`. |
| kinject-android-appcompat | Provides `KinjectAppCompatActivity`. |
| kinject-android-compose | Provides `KinjectComponentActivity`. |
| kinject-compose | Provides the ability to provide an ObjectGraph in a Compose hierarchy. |
| kinject-compose-viewmodel | Provides the ability to get a ViewModel in a compose hierarchy. |
| kinject-compose-voyager | Provides the ability to get a ScreenModel in a compose hierarchy. |
| kinject-coroutines | Provides a `KinjectCoroutineContextElement`, to easily allow passing an `ObjectGraph` via a `CoroutineContext`. |
| kinject-viewmodel | Provides the ability to declare a view model dependency, and a factory to create it. |


## Basic Usage
Expand Down
4 changes: 4 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ lifecycleRuntimeKtx = "2.8.3"
activityCompose = "1.9.0"
appcompat = "1.7.0"
jetbrains-androidx-lifecycle = "2.8.0"
voyager = "1.0.0"

[libraries]
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
Expand All @@ -33,6 +34,9 @@ androidx-lifecycle-viewmodel = { module = "androidx.lifecycle:lifecycle-viewmode
androidx-lifecycle-viewmodel-compose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "androidx-lifecycle" }
jetbrains-androidx-lifecycle-viewmodel = { module = "org.jetbrains.androidx.lifecycle:lifecycle-viewmodel", version.ref = "jetbrains-androidx-lifecycle" }
jetbrains-androidx-lifecycle-viewmodel-compose = { module = "org.jetbrains.androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "jetbrains-androidx-lifecycle" }
voyager-core = { module = "cafe.adriel.voyager:voyager-core", version.ref = "voyager" }
voyager-navigator = { module = "cafe.adriel.voyager:voyager-navigator", version.ref = "voyager" }
voyager-screenModel = { module = "cafe.adriel.voyager:voyager-screenmodel", version.ref = "voyager" }

androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
Expand Down
1 change: 1 addition & 0 deletions kinject-bom/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dependencies {
api(project(":kinject-android-compose"))
api(project(":kinject-compose"))
api(project(":kinject-compose-viewmodel"))
api(project(":kinject-compose-voyager"))
api(project(":kinject-coroutines"))
api(project(":kinject-viewmodel"))
}
Expand Down
17 changes: 17 additions & 0 deletions kinject-compose-voyager/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.compose)
alias(libs.plugins.gradleMavenPublish)
}

android {
namespace = "kinject.compose.voyager"
}

dependencies {
api(project(":kinject-compose"))
implementation(libs.voyager.core)
implementation(libs.voyager.navigator)
implementation(libs.voyager.screenModel)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package kinject.compose.voyager

import androidx.compose.runtime.Composable
import cafe.adriel.voyager.core.model.ScreenModel
import cafe.adriel.voyager.core.model.rememberScreenModel
import cafe.adriel.voyager.core.model.rememberNavigatorScreenModel
import cafe.adriel.voyager.core.screen.Screen
import cafe.adriel.voyager.navigator.Navigator
import kinject.compose.LocalKinjectContext

@Composable
inline fun <reified SM : ScreenModel> Screen.injectScreenModel(): SM {
val smClass = SM::class
val kinjectContext = LocalKinjectContext.current

return rememberScreenModel {
kinjectContext.objectGraph.get(smClass)
}
}

@Composable
inline fun <reified SM : ScreenModel> Navigator.injectNavigatorScreenModel(): SM {
val smClass = SM::class
val kinjectContext = LocalKinjectContext.current

return rememberNavigatorScreenModel {
kinjectContext.objectGraph.get(smClass)
}
}
2 changes: 1 addition & 1 deletion kinject-compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ composeCompiler {

dependencies {
implementation(project(":kinject-core"))
implementation(libs.compose.runtime)
api(libs.compose.runtime)
}
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ include(":kinject-android-compose")
include(":kinject-bom")
include(":kinject-compose")
include(":kinject-compose-viewmodel")
include(":kinject-compose-voyager")
include(":kinject-core")
include(":kinject-coroutines")
include(":kinject-viewmodel")
Expand Down

0 comments on commit 6864795

Please sign in to comment.