Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import org.koin.core.annotation.KoinInternalApi
*/
@KoinExperimentalAPI
@OptIn(KoinInternalApi::class)
fun ComponentCallbacks.entryProvider(
fun <T : Any> ComponentCallbacks.entryProvider(
mode: LazyThreadSafetyMode = LazyThreadSafetyMode.SYNCHRONIZED,
) : Lazy<EntryProvider> = lazy(mode) { getEntryProvider() }
) : Lazy<EntryProvider<T>> = lazy(mode) { getEntryProvider() }

/**
* Retrieves an [EntryProvider] by collecting all [EntryProviderInstaller] instances from the Koin scope
Expand All @@ -42,6 +42,6 @@ fun ComponentCallbacks.entryProvider(
*/
@KoinExperimentalAPI
@OptIn(KoinInternalApi::class)
fun ComponentCallbacks.getEntryProvider() : EntryProvider {
fun <T : Any> ComponentCallbacks.getEntryProvider() : EntryProvider<T> {
return getKoinScope().getEntryProvider()
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.koin.compose.navigation3

import androidx.compose.runtime.Composable
import androidx.navigation3.runtime.EntryProviderScope
import androidx.navigation3.runtime.NavEntry
import androidx.navigation3.runtime.entryProvider
import org.koin.compose.LocalKoinScopeContext
Expand All @@ -33,13 +34,13 @@ import org.koin.core.scope.Scope
* @see EntryProviderInstaller for defining navigation entries in Koin modules
*/
@KoinExperimentalAPI
typealias EntryProvider = (Any) -> NavEntry<Any>
typealias EntryProvider<T> = (T) -> NavEntry<T>

@KoinExperimentalAPI
internal fun Scope.getEntryProvider() : EntryProvider {
internal fun <T : Any> Scope.getEntryProvider() : EntryProvider<T> {
val entries = getAll<EntryProviderInstaller>()
val entryProvider: (Any) -> NavEntry<Any> = entryProvider {
entries.forEach { builder -> this.builder() }
val entryProvider: EntryProvider<T> = entryProvider {
entries.forEach { builder -> (this as EntryProviderScope<Any>).builder() }
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

The unsafe cast to EntryProviderScope<Any> is necessary due to the design where EntryProviderInstaller is hardcoded to EntryProviderScope<Any>. While this works because the navigation3 library's type-safe entry<T> calls handle type matching at registration time, it means that the generic type parameter T on koinEntryProvider<T>() doesn't actually provide compile-time type safety - it only affects the return type signature.

This could be misleading to API consumers who might expect that calling koinEntryProvider<MyNavKey>() would restrict entries to only those registered for MyNavKey. Consider adding a KDoc note explaining that T is a convenience type parameter for the caller's type system and doesn't enforce which entries are included at runtime.

Copilot uses AI. Check for mistakes.
}
return entryProvider
}
Expand Down Expand Up @@ -71,6 +72,6 @@ internal fun Scope.getEntryProvider() : EntryProvider {
@OptIn(KoinInternalApi::class)
@KoinExperimentalAPI
@Composable
fun koinEntryProvider(scope : Scope = LocalKoinScopeContext.current.getValue()) : EntryProvider {
fun <T : Any> koinEntryProvider(scope : Scope = LocalKoinScopeContext.current.getValue()) : EntryProvider<T> {
return scope.getEntryProvider()
}
Loading