Skip to content

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 optional scroll event callback, allowing external actions when the grid is scrolled.
  • Refactor

    • Improved scroll performance and virtualization updates by introducing throttled scroll handling with an animated scroll view.

@coderabbitai
Copy link

coderabbitai bot commented Apr 29, 2025

Walkthrough

The changes introduce throttled scroll event handling to the ResponsiveGrid component. A new useThrottle hook is used to limit the frequency of scroll processing to every 32ms. The scroll handler now also supports an optional external onScroll callback prop, which is invoked with the scroll event if provided. The virtualization logic for updating visible items is now called within the throttled handler. The scrollEventThrottle prop was removed from the underlying ScrollView. Type definitions were updated to reflect the new onScroll prop. Additionally, the ScrollView was replaced with Animated.ScrollView from react-native-reanimated. The package dependencies were updated to include react-native-reanimated.

Changes

File(s) Change Summary
src/responsive-grid/index.tsx Refactored scroll handling to use throttling, added support for external onScroll callback, updated virtualization logic, replaced ScrollView with Animated.ScrollView, and removed explicit scrollEventThrottle prop.
src/responsive-grid/types.ts Added optional onScroll callback to ResponsiveGridProps interface and imported ReanimatedScrollEvent type.
package.json Added react-native-reanimated as a devDependency and peerDependency.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant AnimatedScrollView
    participant ResponsiveGrid
    participant useThrottle
    participant Virtualization

    User->>AnimatedScrollView: Scrolls
    AnimatedScrollView->>ResponsiveGrid: onScroll event
    ResponsiveGrid->>ResponsiveGrid: Call external onScroll prop (if provided)
    ResponsiveGrid->>useThrottle: Throttle onScroll handling (32ms)
    useThrottle-->>ResponsiveGrid: Throttled scroll event
    ResponsiveGrid->>ResponsiveGrid: Update scroll position & check onEndReached
    ResponsiveGrid->>Virtualization: Update visible items (if enabled)
Loading

Poem

In grids that scroll both left and right,
A rabbit adds some throttled might.
Now scroll events come, but not too fast—
Each hop is measured, built to last.
With callbacks new and code refined,
The grid keeps pace, and hops aligned!
🐇✨


📜 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 be85754 and 8b5dd8c.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (3)
  • package.json (2 hunks)
  • src/responsive-grid/index.tsx (6 hunks)
  • src/responsive-grid/types.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • package.json
  • src/responsive-grid/types.ts
  • src/responsive-grid/index.tsx
✨ 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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
package.json (1)

75-76: Constrain peerDependency version range for react-native-reanimated
Currently the peerDependency is "react-native-reanimated": "*", which could inadvertently allow incompatible future versions. It’s safer to pin this to the tested major/minor range. For example:

-  "react-native-reanimated": "*"
+  "react-native-reanimated": "^3.17.5"

This adjustment helps prevent breaking changes when major updates of Reanimated are released.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5a2129d and be85754.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (2)
  • package.json (2 hunks)
  • src/responsive-grid/index.tsx (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/responsive-grid/index.tsx
🔇 Additional comments (1)
package.json (1)

70-70: Verify addition of react-native-reanimated in devDependencies
The devDependencies block now includes "react-native-reanimated": "^3.17.5", which is required for building and type‐checking with Reanimated. Confirm that this version aligns with the one used in your example workspace and any local TS configurations.

@iNerdStack
Copy link
Owner

@robgraeber
Thank you for your contribution.
I will review this fully before the end of the day

One thing to talk about, the second commit introduces re-animated, it is a great idea, but the aim of this package was to aim for zero dependency since it's also focused on compatibility across mobile and web.

I would also want to know if there's an avoidable need to add this dependency? Let me know your thoughts

@robgraeber
Copy link
Contributor Author

Sorry didn't to pull in the reanimated changes. I made another PR with just the onScroll prop: #71

Regarding the reanimated changes, using the default scroll view's onScroll has a one frame delay so if you move the scrollview up and down quickly there's a few pixels of lag between the header position and the scroll position. The native onScroll should be fine for most though.

If you did want to add Reanimated, it would support web I believe but it'd be a breaking change as it'd add a peer dependency. I was planning to keep the reanimated stuff to my own fork.

@robgraeber robgraeber closed this Apr 29, 2025
@iNerdStack
Copy link
Owner

Great @robgraeber

Thanks again for your contribution and the explanation!

I really appreciate the idea of introducing Reanimated and the clarification around the scroll performance issue. You're right — Reanimated does offer smoother & native-driven animations

That said, for now, I think it's best to keep the core package zero-dependency to maximize compatibility and keep it lightweight for both mobile and web users. However, your suggestion has definitely opened up a new roadmap forward.

We can consider introducing a separate package — something like an animated version — that would live alongside the core package and offer enhanced features using Reanimated. This way we can support more advanced use cases like draggable items and smoother animated layouts without affecting users who prefer a minimal setup.

We might structure that separate package or extract the enhancements in a modular way under the same context (e.g., shared types, core logic, etc.).

Thanks again, and feel free to share any ideas you have around this direction!

@ahundt
Copy link

ahundt commented Jul 7, 2025

@robgraeber is that draggable fork of the grid available somewhere?

@robgraeber
Copy link
Contributor Author

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.

3 participants