Skip to content

Add onScroll prop #71

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

Merged
merged 1 commit into from
May 3, 2025
Merged

Conversation

robgraeber
Copy link
Contributor

@robgraeber robgraeber commented Apr 29, 2025

Hi there,

I added a prop exposing the onScroll handler for the scroll view. This is useful for disappearing page headers that scroll along with the page. Why not a header component? In my case I'm adjusting the header opacity as it scrolls.

I also refactored the scrollEventThrottle so the onScroll prop is unthrottled, this is necessary for smooth animations.

Summary by CodeRabbit

  • New Features

    • Added support for an external scroll event handler in the ResponsiveGrid component, allowing custom actions when the grid is scrolled.
  • Refactor

    • Improved scroll event handling with internal throttling for smoother performance and more efficient virtualization updates.

Copy link

coderabbitai bot commented Apr 29, 2025

Walkthrough

The changes refactor the scroll handling logic in the ResponsiveGrid component by introducing throttling for internal scroll events and supporting an external scroll event handler via a new onScroll prop. The throttling is implemented using a custom hook with a 32ms interval to optimize performance. The scroll event handler logic was updated to invoke both the internal throttled handler and any external handler provided. The scrollEventThrottle prop was removed from the ScrollView, as internal throttling now manages event frequency. Type definitions were updated to reflect the new optional onScroll prop.

Changes

File(s) Change Summary
src/responsive-grid/index.tsx Refactored scroll handling: added internal throttling, supported external scroll handler, removed scrollEventThrottle, updated logic for onEndReached and virtualization updates.
src/responsive-grid/types.ts Added onScroll optional callback to ResponsiveGridProps interface, updated imports for event types.

Poem

A grid that scrolls, now swift and bright,
With throttled moves, it feels just right.
Invite your own scroll handler in—
The code’s more nimble, lean, and thin.
As rabbits hop from here to there,
The grid keeps up, light as air! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4fdcaa4 and 5e27c9d.

📒 Files selected for processing (2)
  • src/responsive-grid/index.tsx (2 hunks)
  • src/responsive-grid/types.ts (2 hunks)
🔇 Additional comments (6)
src/responsive-grid/types.ts (2)

3-8: Clean and proper type imports.

The addition of NativeScrollEvent and NativeSyntheticEvent types is necessary for the new onScroll prop and follows good practices by importing specific types rather than the entire module.


57-59: Well-documented onScroll prop.

The type definition and documentation for the new onScroll prop are correct and align with React Native's scroll event callback pattern. The JSDoc comment clearly describes the prop's purpose.

src/responsive-grid/index.tsx (4)

24-24: Good parameter renaming for clarity.

Renaming the prop to onScrollProp during destructuring helps avoid naming conflicts with the internal onScroll function, making the code more maintainable.


87-117: Well-implemented throttled scroll handler.

The implementation of throttledOnScroll effectively separates internal scroll handling logic with appropriate throttling. The 32ms throttle interval is a good choice for responsive scroll animations while preventing excessive renders.

Note that this throttle interval (32ms) differs from the scrollEventInterval (200ms) used for virtualization updates, which appears intentional to balance UI responsiveness with performance.


119-125: Proper forwarding of scroll events.

This implementation correctly forwards scroll events to both the external handler and the internal throttled handler. Calling the external handler first allows consumers to access the raw event before any internal processing occurs.


159-160: Note about ScrollView configuration.

The PR removed the scrollEventThrottle prop from the ScrollView (which would normally be here), replacing it with the custom throttling implementation. This change allows the component to receive all scroll events without native throttling, which is essential for smooth animations in the parent component.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@robgraeber robgraeber mentioned this pull request Apr 29, 2025
@iNerdStack
Copy link
Owner

LGTM!
Thank you for adding this!

@iNerdStack iNerdStack merged commit d8b91cc into iNerdStack:main May 3, 2025
6 checks passed
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