-
-
Notifications
You must be signed in to change notification settings - Fork 759
Fix sharedKoinViewModel fails with type-safe navigation routes #2293
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: main
Are you sure you want to change the base?
Conversation
|
I don't see why it bring stronger verification here, as the compiler should already help here. |
|
@arnaudgiuliani |
|
Do you have a test case to reproduce, something we can add into examples project, the android compose app? |
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 fixes a bug where sharedKoinViewModel fails when using type-safe navigation routes. The fix adds conditional handling to support both string-based and type-safe (object-based) navigation routes.
- Adds type checking to handle both String and non-String route types
- Ensures
getBackStackEntryis called appropriately for both route formats
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| if (navGraphRoute is String) { | ||
| navController.getBackStackEntry(navGraphRoute) | ||
| } else { | ||
| navController.getBackStackEntry(navGraphRoute) | ||
| } |
Copilot
AI
Oct 21, 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.
Both branches of the if-else statement execute identical code. The conditional check serves no purpose and should be removed, leaving only navController.getBackStackEntry(navGraphRoute).
| if (navGraphRoute is String) { | |
| navController.getBackStackEntry(navGraphRoute) | |
| } else { | |
| navController.getBackStackEntry(navGraphRoute) | |
| } | |
| navController.getBackStackEntry(navGraphRoute) |
|
@arnaudgiuliani Added:
You can test it by running the app and tapping "(>)Type Safe Navigation Example" or "(>)String Navigation Example". Both examples demonstrate that screens share the same ViewModel |
Fix sharedKoinViewModel fails with type-safe navigation routes #2292