-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
compose/src/main/kotlin/app/meetacy/di/android/compose/navigation/NavController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters