Skip to content

Commit

Permalink
feat: di for navigation implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
y9san9 committed Feb 18, 2024
1 parent 70a1fca commit ed39da3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 2 additions & 0 deletions compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ android {
dependencies {
api(projects.android)
implementation(libs.composeRuntime)
implementation(libs.navigationCompose)
implementation(libs.navigationUi)
implementation(libs.lifecycleComposeViewmodel)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package app.meetacy.di.android.compose.navigation

import androidx.compose.runtime.*
import androidx.navigation.NavController
import app.meetacy.di.DI
import app.meetacy.di.builder.di
import app.meetacy.di.dependency.Dependency

public val DI.navController: NavController by Dependency

@PublishedApi
internal val LocalNavController: ProvidableCompositionLocal<NavController> =
compositionLocalOf {
error("Please call `buildNavigationDI(...)` only inside `NavigationScreen { ... }`")
}

@Composable
public fun NavigationScreen(
controller: NavController,
block: @Composable () -> Unit
) {
CompositionLocalProvider(
LocalNavController provides controller,
content = block
)
}

public fun buildNavigationDI(di: DI): DI = di + di {
val navController by provider { LocalNavController.current }
}
6 changes: 5 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ kotlin = "1.9.21"
androidGradle = "7.3.0"
composeRuntime = "1.3.3"
composeCompiler = "1.5.6"
androidxNavigation = "2.7.7"
lifecycle = "2.6.1"

mdi = "0.0.31"
mdi = "0.0.32"

[libraries]

composeRuntime = { module = "androidx.compose.runtime:runtime", version.ref = "composeRuntime" }
navigationUi = { module = "androidx.navigation:navigation-ui-ktx", version.ref = "androidxNavigation" }
navigationCompose = { module = "androidx.navigation:navigation-compose", version.ref = "androidxNavigation" }

lifecycleComposeViewmodel = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "lifecycle" }

# gradle plugins
Expand Down

0 comments on commit ed39da3

Please sign in to comment.