Skip to content

Migrate remaining Compose side-effects snippets#832

Open
kkuan2011 wants to merge 1 commit intomainfrom
katherinekuan/compose-side-effects-snippets
Open

Migrate remaining Compose side-effects snippets#832
kkuan2011 wants to merge 1 commit intomainfrom
katherinekuan/compose-side-effects-snippets

Conversation

@kkuan2011
Copy link
Contributor

Code snippets are for:

Snippets not migrated:

  • Line 297 because it is pseudocode

@kkuan2011 kkuan2011 requested a review from a team as a code owner March 12, 2026 00:13
@snippet-bot
Copy link

snippet-bot bot commented Mar 12, 2026

Here is the summary of changes.

You are about to add 2 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@google-cla
Copy link

google-cla bot commented Mar 12, 2026

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.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 completes the migration of several Compose side-effects code snippets from the Android Developer documentation into the project's snippet collection. The changes introduce practical examples for snapshotFlow to observe UI state changes as a Flow and demonstrate best practices for managing effects that need to restart based on lifecycle events using DisposableEffect and rememberUpdatedState. This enhances the educational content available for Compose developers.

Highlights

  • Snippet Migration: Migrated remaining Compose side-effects code snippets from the official Android Developer documentation, specifically for the side-effects page.
  • New snapshotFlow Example: Added a new example demonstrating the usage of snapshotFlow to convert Compose State into a Kotlin Flow, specifically tracking LazyColumn scroll state for analytics.
  • New Restarting Effects Example: Included a new snippet illustrating how to handle restarting effects using DisposableEffect and rememberUpdatedState for lifecycle-aware event handling.
  • Exclusion of Pseudocode: One snippet (line 297) was intentionally not migrated as it was identified as pseudocode.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • compose/snippets/src/main/java/com/example/compose/snippets/sideeffects/SideEffectsSnippets.kt
    • Added imports for snapshotFlow and Kotlin Flow operators (distinctUntilChanged, filter, map).
    • Implemented SnapshotFlowExample to demonstrate converting LazyListState into a Flow for analytics.
    • Implemented RestartingEffectsSnippet showcasing DisposableEffect with rememberUpdatedState for lifecycle event handling.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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

  1. 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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 migrates two new code snippets for the Compose side-effects documentation: SnapshotFlowExample and RestartingEffectsSnippet. My review focuses on improving the clarity and correctness of these new snippets. I've suggested a stylistic improvement to make the Flow chain more idiomatic in SnapshotFlowExample, and corrected a misleading comment in RestartingEffectsSnippet to avoid confusion for developers reading the documentation.

snapshotFlow { listState.firstVisibleItemIndex }
.map { index -> index > 0 }
.distinctUntilChanged()
.filter { it == true }
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For boolean flows, filter { it == true } can be simplified to filter { it } for better readability and conciseness. This is a common idiomatic expression in Kotlin.

Suggested change
.filter { it == true }
.filter { it }

onStart: () -> Unit, // Send the 'started' analytics event
onStop: () -> Unit // Send the 'stopped' analytics event
) {
// These values never change in Composition
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This comment is misleading. The values held by currentOnStart and currentOnStop are updated on every recomposition, which is the purpose of rememberUpdatedState. The benefit is that using them inside an effect does not cause the effect to restart. A more accurate comment, like the one used in the other HomeScreen example in this file, would be clearer.

Suggested change
// These values never change in Composition
// Safely update the current lambdas when a new one is provided

@kkuan2011 kkuan2011 force-pushed the katherinekuan/compose-side-effects-snippets branch from 5ea4378 to 9766f96 Compare March 12, 2026 04:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant