Skip to content

Bugfix/pull to refresh#1670

Open
EvangelosG wants to merge 4 commits intoandroid:mainfrom
EvangelosG:bugfix/pull-to-refresh
Open

Bugfix/pull to refresh#1670
EvangelosG wants to merge 4 commits intoandroid:mainfrom
EvangelosG:bugfix/pull-to-refresh

Conversation

@EvangelosG
Copy link

Fix pull-to-refresh activating from continuous scroll-to-top gesture in JetNews app.

PullToRefreshBox triggers on any overscroll with NestedScrollSource.UserInput,
which means dragging from the bottom of the list to the top in a single gesture
incorrectly activates refresh once the list hits its top bound.

Add a NestedScrollConnection above PullToRefreshBox that tracks whether the
child consumed any downward scroll during the current gesture. If it did, the
gesture started mid-list, so overscroll is consumed to prevent PullToRefreshBox
from seeing it. The flag resets on fling (finger lift) so the next fresh
pull-down from the top still works normally.

@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 resolves an unintended behavior in the JetNews app where the pull-to-refresh mechanism would trigger even when a user was scrolling up from the middle of a list. By implementing a custom nested scroll connection, the application now intelligently distinguishes between a deliberate pull-down from the top and a continuous scroll, ensuring the refresh action is only initiated under the correct conditions, thereby improving user experience.

Highlights

  • Bugfix for Pull-to-Refresh: Resolved an issue where the pull-to-refresh mechanism in the JetNews app would incorrectly activate during a continuous scroll-to-top gesture, even if the scroll originated from the middle of the list.
  • Nested Scroll Connection Implementation: Introduced a custom NestedScrollConnection named guardConnection to intelligently manage scroll events before they reach the PullToRefreshBox.
  • Conditional Overscroll Consumption: The guardConnection tracks if the child composable consumed any downward scroll within the current gesture. If so, it consumes any subsequent overscroll, preventing the PullToRefreshBox from triggering unless the gesture explicitly starts at the top of the list.
  • Gesture Reset Logic: The scrolledInCurrentGesture flag within the NestedScrollConnection is reset upon onPreFling (when the finger is lifted), ensuring that a fresh pull-down gesture from the top of the list can still correctly activate the refresh.

🧠 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
  • JetNews/app/src/main/java/com/example/jetnews/ui/home/HomeScreens.kt
    • Added necessary imports for Offset, NestedScrollConnection, NestedScrollSource, and Velocity to support nested scrolling logic.
    • Implemented a remember block to create a NestedScrollConnection instance (guardConnection) that tracks scroll activity within a gesture.
    • Modified the PullToRefreshBox content to be wrapped in a Box that applies the new guardConnection using the nestedScroll modifier, effectively guarding the refresh mechanism.
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 effectively resolves an issue where pull-to-refresh was incorrectly triggered during a continuous scroll-to-top gesture. The solution, which involves a custom NestedScrollConnection to conditionally consume overscroll, is well-implemented and directly addresses the problem. The code is clear and includes helpful comments explaining the logic. I have one minor suggestion to enhance readability.

Early-return when the scroll source is not UserInput instead of
wrapping the body in a conditional block. No behavior change.
@riggaroo
Copy link
Collaborator

@raystatic Can you take a look at if this is a valid bug and a valid fix for the bug or if we need to file an issue internally? Thanks

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.

2 participants