-
Notifications
You must be signed in to change notification settings - Fork 70
Koin Navigation3 Integration #118
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
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Summary of ChangesHello @arnaudgiuliani, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request integrates Koin as a dependency injection framework for modular navigation within the Navigation3 library. It provides a complete example of how to structure an Android application with Koin-driven feature modules, each defining its own navigation entries. This offers developers a clear alternative to the existing Hilt-based modular navigation example, promoting flexibility in DI choices while maintaining a clean, modular architecture. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request successfully integrates Koin for modular navigation, providing a valuable example alongside the existing Hilt implementation. The new modules and activity are well-structured. My review includes a few suggestions to improve the code. The most important feedback relates to the Koin initialization strategy, which, while functional for this sample app, follows a pattern that is not recommended for production applications. I've also noted a documentation comment that appears to be a copy-paste from the Hilt example and should be corrected for clarity.
| if (KoinPlatform.getKoinOrNull() != null) { | ||
| stopKoin() | ||
| } | ||
| // The startKoin block should be placed in Application.onCreate. | ||
| startKoin { | ||
| androidContext(this@KoinModularActivity) | ||
| modules(appModule) | ||
| } |
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.
Initializing Koin within an Activity's onCreate method, especially with stopKoin(), is not a recommended practice for production applications. It can lead to performance issues and unpredictable behavior if multiple components rely on a stable Koin container. While this approach may be necessary for the isolated nature of these recipe examples, it's crucial to highlight that in a real-world app, startKoin should be called only once, typically in your Application class's onCreate method. Please consider adding a more prominent warning in the KDoc or a code comment to prevent developers from copying this pattern into production code.
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.
this part is to help local sample, of course not advised to to so in normal app setup
| //prevent any already launched Koin instance with other config | ||
| if (KoinPlatform.getKoinOrNull() != null) { | ||
| stopKoin() | ||
| } | ||
| // The startKoin block should be placed in Application.onCreate. | ||
| if (GlobalContext.getOrNull() == null) { | ||
| GlobalContext.startKoin { | ||
| androidContext(this@KoinViewModelsActivity) | ||
| modules( | ||
| module { | ||
| viewModelOf(::RouteBViewModel) | ||
| } | ||
| ) | ||
| } | ||
| startKoin { | ||
| androidContext(this@KoinViewModelsActivity) | ||
| modules( | ||
| module { | ||
| viewModelOf(::RouteBViewModel) | ||
| } | ||
| ) | ||
| } |
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.
Similar to the other Koin activity, re-initializing Koin in onCreate by calling stopKoin() and startKoin() is an anti-pattern. This can cause performance degradation and unexpected behavior in a real application where a consistent dependency graph is expected. It's a best practice to initialize Koin once in the Application class. Please add a comment to warn developers against using this pattern in production code.
app/src/main/java/com/example/nav3recipes/modular/koin/KoinModularActivity.kt
Outdated
Show resolved
Hide resolved
…ularActivity.kt Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
done CLA update for my profile |
pedrofsn
left a comment
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.
LGTM
|
Is it possible to pass metadata to the entry using the new navigation dsl? |
danysantiago
left a comment
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.
LGTM - Thanks!
| * A shared `Navigator` class manages the backstack. | ||
| * | ||
| * The `appModule` includes the feature modules, creates the `Navigator` with a start destination, | ||
| * and makes it available for injection into the `KoinModularActivity` and feature modules. |
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.
I would also add one more sentence about how the NavDisplay's is then setup with an EntryProvider from's Koin feature extension koin-compose-navigation3 (i.e. the getEntryProvider Koin function).
This PR proposes Koin Navigation 3 integration usages:
Module navigation entry declaration (within Activity scope) with
navigationfunction:Allow to inject directly the
EntryProviderfrom Activity:Key Changes
New Files
Refactoring
Configuration Updates
Architecture
The implementation follows a modular pattern where: