Skip to content

Conversation

@arnaudgiuliani
Copy link
Member

Add Navigation 3 Integration for Koin Compose

Overview

Adds support for AndroidX Navigation 3 with type-safe navigation integration for Koin Compose (multiplatform).

What's New

  • New module: koin-compose-navigation3 - Multiplatform Navigation 3 integration
  • Experimental API: @KoinExperimentalAPI - Navigation 3 is currently in beta
  • Type-safe navigation: Use serializable routes with Koin dependency injection

Key Features

  1. Navigation DSL
module {
    navigation<HomeRoute> { route ->
        HomeScreen(viewModel = koinViewModel())
    }
}
  1. Android Extensions
class MainActivity : ComponentActivity() {

  override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      val entryProvider = getEntryProvider()

      setContent {
          NavigationHost(
              entryProvider = entryProvider,
              startDestination = HomeRoute
          )
      }
  }
}
  1. Compose API
@Composable
fun App() {
    val entryProvider = koinEntryProvider()
    NavigationHost(entryProvider, startDestination = HomeRoute)
}

Documentation

documentation in /docs/reference/koin-compose/navigation3.md

Platform Support

Android • JVM • JS • WASM • iOS • macOS

Dependencies Used

Dependencies used:

  • androidx.navigation3:navigation3-runtime:1.0.0-beta01

Fix #2286

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for AndroidX Navigation 3 integration in Koin, along with a bug fix for the getAll() function when working with scope archetypes. The changes introduce a new module for Navigation 3 integration and fix an issue where getAll() wasn't properly checking scope archetypes.

  • Added new koin-compose-navigation3 module with Navigation 3 integration APIs
  • Fixed getAll() to properly resolve instances from scope archetypes
  • Added comprehensive documentation for Navigation 3 integration

Reviewed Changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
projects/settings.gradle.kts Added koin-compose-navigation3 module to the build
projects/gradle/libs.versions.toml Added Navigation 3 dependency version and library reference
projects/gradle.properties Updated Koin version and added androidComposeMinSDK property
projects/core/koin-core/src/commonTest/kotlin/org/koin/core/GetAllTest.kt Added tests for getAll() functionality with scopes
projects/core/koin-core/src/commonMain/kotlin/org/koin/core/scope/Scope.kt Fixed getAll() to set scopeArchetype in resolution context
projects/core/koin-core/src/commonMain/kotlin/org/koin/core/registry/InstanceRegistry.kt Fixed getAll() filter to check scope archetype
projects/core/koin-core/build.gradle.kts Added JVM toolchain configuration
projects/compose/koin-compose-navigation3/src/commonMain/kotlin/org/koin/dsl/navigation3/ModuleExt.kt New DSL functions for declaring navigation entries
projects/compose/koin-compose-navigation3/src/commonMain/kotlin/org/koin/compose/navigation3/EntryProviderInstaller.kt Type alias for navigation entry installation
projects/compose/koin-compose-navigation3/src/commonMain/kotlin/org/koin/compose/navigation3/EntryProvider.kt EntryProvider implementation and koinEntryProvider composable
projects/compose/koin-compose-navigation3/src/androidMain/kotlin/org/koin/androidx/compose/navigation3/ComponentCallbacksExt.kt Android-specific ComponentCallbacks extensions
projects/compose/koin-compose-navigation3/build.gradle.kts Build configuration for the new module
projects/bom/koin-bom/build.gradle.kts Added navigation3 module to BOM
projects/android/koin-android/src/test/java/org/koin/core/scope/ActivityScopeArchetypeTest.kt Added test for getAll() with activity scope archetypes
docs/reference/koin-compose/navigation3.md Comprehensive documentation for Navigation 3 integration

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

#Android
android.useAndroidX=true
androidMinSDK=21
androidComposeMinSDK=23
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new property androidComposeMinSDK is defined but never used in the codebase. The koin-compose-navigation3 module at line 62 of projects/compose/koin-compose-navigation3/build.gradle.kts uses androidMinSDK instead of androidComposeMinSDK. Either use this property in the appropriate build files or remove it.

Suggested change
androidComposeMinSDK=23

Copilot uses AI. Check for mistakes.

data class MyScope(val name : String)

//TODO GetAll sur scope archetype - fail?
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment contains French text 'sur' which should be 'on' in English. Consider changing to '//TODO GetAll on scope archetype - fail?' for consistency with the codebase language.

Suggested change
//TODO GetAll sur scope archetype - fail?
//TODO GetAll on scope archetype - fail?

Copilot uses AI. Check for mistakes.
val activityScope = activity.scope

val entries = activityScope.getAll<Entry>()
assertEquals(3,entries.size)
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Missing space after comma in function arguments. Should be assertEquals(3, entries.size) for consistency with Kotlin code style.

Suggested change
assertEquals(3,entries.size)
assertEquals(3, entries.size)

Copilot uses AI. Check for mistakes.
* @return An [EntryProvider] that combines all registered navigation entries
*
* @see entryProvider for lazy initialization
* @See ComponentCallbacks
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation tag @See should be lowercase @see to match KDoc conventions and be consistent with line 40.

Suggested change
* @See ComponentCallbacks
* @see ComponentCallbacks

Copilot uses AI. Check for mistakes.
}.koin

val entries = koin.getAll<Entry>()
assertEquals(3,entries.size)
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Missing space after comma in function arguments. Should be assertEquals(3, entries.size) for consistency with Kotlin code style.

Suggested change
assertEquals(3,entries.size)
assertEquals(3, entries.size)

Copilot uses AI. Check for mistakes.
}.koin
val scope = koin.createScope<MyScope>()
val entries = scope.getAll<Entry>()
assertEquals(3,entries.size)
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Missing space after comma in function arguments. Should be assertEquals(3, entries.size) for consistency with Kotlin code style.

Suggested change
assertEquals(3,entries.size)
assertEquals(3, entries.size)

Copilot uses AI. Check for mistakes.
Comment on lines +258 to +259
assertEquals(3,entries.size)
assertEquals((1..3).map { Entry("entry_$it") },entries)
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Missing space after comma in function arguments. Should be assertEquals((1..3).map { Entry(\"entry_$it\") }, entries) for consistency with Kotlin code style.

Suggested change
assertEquals(3,entries.size)
assertEquals((1..3).map { Entry("entry_$it") },entries)
assertEquals(3, entries.size)
assertEquals((1..3).map { Entry("entry_$it") }, entries)

Copilot uses AI. Check for mistakes.
@arnaudgiuliani arnaudgiuliani merged commit bdf8959 into 4.2.0 Nov 3, 2025
4 checks passed
@arnaudgiuliani arnaudgiuliani deleted the 2286_feat_nav3 branch November 5, 2025 11:40
Copy link
Contributor

@pedrofsn pedrofsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants