-
-
Notifications
You must be signed in to change notification settings - Fork 771
Make nav3 entryprovider generic #2314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 4.2.0
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 makes the EntryProvider type and related functions generic to improve ergonomics when using typed navigation backstacks with Navigation3. Previously, users had to manually cast koinEntryProvider() when working with typed backstacks (e.g., List<MyNavKey>), which was verbose and error-prone. The changes add a generic type parameter <T : Any> throughout the API surface.
Key Changes:
- Made
EntryProvidertypealias generic:EntryProvider<T> = (T) -> NavEntry<T> - Added generic type parameters to
koinEntryProvider,Scope.getEntryProvider, and Android-specific extension functions - Added import for
EntryProviderScopeto support the cast needed for backward compatibility with the non-genericEntryProviderInstaller
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
projects/compose/koin-compose-navigation3/src/commonMain/kotlin/org/koin/compose/navigation3/EntryProvider.kt |
Core changes: made EntryProvider generic, added type parameters to functions, added cast to maintain compatibility with EntryProviderInstaller |
projects/compose/koin-compose-navigation3/src/androidMain/kotlin/org/koin/androidx/compose/navigation3/ComponentCallbacksExt.kt |
Android-specific extensions updated with generic type parameters to match the core changes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| val entryProvider: (Any) -> NavEntry<Any> = entryProvider { | ||
| entries.forEach { builder -> this.builder() } | ||
| val entryProvider: EntryProvider<T> = entryProvider { | ||
| entries.forEach { builder -> (this as EntryProviderScope<Any>).builder() } |
Copilot
AI
Dec 9, 2025
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
The current implementation does not allow using
koinEntryProviderwhen the backstack items type is notAny.As a result, it’s necessary to manually cast the returned value:
This PR removes that limitation and allows
koinEntryProviderto work with typed backstack.