-
Notifications
You must be signed in to change notification settings - Fork 63
Add recipes for returning navigation results #65
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
* main: Remove comments Add headings to the recipe picker Fix typo Add a recipe for creating dialogs. Add CODEOWNERS Add build workflow
* main: Update library versions Remove the extra blank line at end of CODEOWNERS file Update CODEOWNERS file
…tate through config changes
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.
Summary of Changes
Hello @jbw0033, 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 introduces two new recipes that demonstrate different approaches to returning results between navigation destinations in a Compose application. The first recipe, 'Return result as Event', leverages a ResultStore
backed by Kotlin Channel
s, allowing a screen to send a result that a previous screen can observe using a ResultEffect
composable. The second recipe, 'Return result as State', uses a rememberResult
composable to manage a hoisted mutable state, enabling a child screen to directly update a value that the parent screen can react to. Additionally, this PR includes a new markdown guide, Nav2ToNav3Snippets.md
, which provides extensive code snippets and explanations for migrating existing Navigation 2 patterns to the Navigation 3 framework, covering a wide range of navigation functionalities.
Highlights
- New Navigation Result Recipes: Introduced two distinct methods for returning results from a navigated screen back to a previous one: one utilizing a
ResultStore
with KotlinChannel
s for event-based results, and another employing arememberResult
composable for state-based results. - Navigation Migration Guide: Added a comprehensive markdown document,
Nav2ToNav3Snippets.md
, which serves as a detailed guide for developers transitioning from Navigation 2 to Navigation 3, providing side-by-side code examples for various navigation patterns.
Using Gemini Code Assist
The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
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 .gemini/
folder in the base of the repository. Detailed instructions can be found here.
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
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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 introduces two new recipes for returning results between screens, one using an event-based approach with Channel
and another using a hoisted State
. The implementation is a good starting point, but there are several critical issues related to state management in Compose, potential runtime crashes due to unsafe type casting, and incorrect usage of CompositionLocal
. I've provided detailed comments and suggestions to address these issues, which will improve the robustness and correctness of the new recipes.
app/src/main/java/com/example/nav3recipes/results/event/ResultStore.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/com/example/nav3recipes/results/event/ResultEventActivity.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/com/example/nav3recipes/results/state/ResultStateActivity.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/com/example/nav3recipes/results/event/ResultEventActivity.kt
Show resolved
Hide resolved
app/src/main/java/com/example/nav3recipes/results/state/ResultStateActivity.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/com/example/nav3recipes/results/event/ResultStore.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/com/example/nav3recipes/results/state/Result.kt
Outdated
Show resolved
Hide resolved
Nice, I've been waiting for this pr for a while 😄 This will help solve my comment at #34 (comment) |
Could it be possible to return a parameterized Result<S, E> class? |
This commit adds two new recipes demonstrating how to return a result from one screen to a previous one. The "Return result as Event" recipe uses a `ResultStore` backed by Kotlin `Channel`s. A screen can send a result, and the previous screen can listen for it using a `ResultEffect` composable. The "Return result as State" recipe uses a `rememberResult` composable, which wraps `mutableStateOf`. The state is hoisted and can be updated by a child screen.
Move Material recipes to their specific package
Adding a compose to assist in remembering the store across config changes.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
* main: (21 commits) Update README.md Update README.md Update README.md Update README.md Update README.md Move Material recipes to their specific package Addressing AI code review Slight formatting change Add koin injected ViewModel recipe Fix naming Update README file Fix comments Fix comments Update dependencies to sync with Supporting Pane PR Create Supporting Pane Recipe Create Supporting Pane Recipe Add link to bug Address Gemini feedback Replace SnapshotStateList with NavBackStack Update to latest library versions and disable snapshot artifact repo ...
# Conflicts: # app/src/main/AndroidManifest.xml # app/src/main/java/com/example/nav3recipes/RecipePickerActivity.kt
Update to alpha10
* main: Update gradle/libs.versions.toml Update to alpha10
This PR adds a migration guide for navigating from Navigation Compose (aka Nav2) to Navigation 3. It includes a guide and accompanying code recipes in the `migration` package.
# Conflicts: # app/src/main/AndroidManifest.xml
Co-authored-by: Ola Bråten <[email protected]>
@Olabraaten - can you please sign the CLA then run the rescan? That would help fix the last failing check. |
This commit adds two new recipes demonstrating how to return a result
from one screen to a previous one.
The "Return result as Event" recipe uses a
ResultStore
backed byKotlin
Channel
s. A screen can send a result, and the previous screencan listen for it using a
ResultEffect
composable.The "Return result as State" recipe uses a
rememberResult
composable,which wraps
mutableStateOf
. The state is hoisted and can be updatedby a child screen.