CardScroller
A horizontal scrolling container for card-based content with optional title and "See all" link.
CardScroller
The CardScroller component provides a horizontal scrolling container perfect for displaying card elements, product listings, or any horizontally scrollable content. It includes options for a title, "See all" link, and snap-to-grid scrolling behavior.
Features
- Horizontal Scrolling: Smooth horizontal scrolling for card elements
- Optional Title: Display a section title above the scrolling content
- See All Link: Optional link to a view with all content items
- Snap Scrolling: Optional snap-to-grid scrolling behavior
- Customizable Spacing: Control the gap between scrolling items
- Styling Options: Custom classes and styles for flexible design
Import
Props
Prop | Type | Default | Description |
---|---|---|---|
title | string | — | Optional title displayed above the scrolling content |
img | string | — | Optional image URL (currently not used in the component) |
allUrl | string | — | URL for the "See all" link, if not provided the link won't be shown |
enableSnapping | boolean | false | Whether to enable snap-to-grid scrolling behavior |
snapInterval | number | 0 | Distance between snap points when snapping is enabled |
className | string | — | Additional Tailwind classes for the container |
style | ViewStyle | — | Additional style object for more customization |
space | number | 10 | Space between items in the scroll view |
children | ReactNode | Required | Content to render within the scroll view |
Usage Examples
Basic Card Scroller
With "See All" Link
With Snap Scrolling
Custom Styling
Integration Examples
Home Screen Featured Items
E-commerce Product Recommendations
Multiple CardScrollers with Different Content Types
Best Practices
Consistent Card Sizes
For the best visual appearance and scroll behavior, maintain consistent sizes for cards within a CardScroller:
Use Appropriate Spacing
Adjust spacing based on card size and content density:
Enable Snapping for Better UX
When cards have a consistent width, enable snapping for a more polished user experience:
Implementation Details
The CardScroller component is built using React Native's ScrollView with horizontal scrolling enabled. It provides a container that handles horizontal overflow with proper padding and spacing between items.
The component renders an optional title and "See all" link at the top, which are aligned on opposite sides of the container. The "See all" link includes an underline animation for better visual feedback.
The scroll container uses negative margin and padding to ensure the scrolling content aligns properly with the rest of the UI while maintaining padding within the scroll area. This approach prevents the need for additional wrapper components.
For snapping behavior, the component uses ScrollView's snapToInterval
and decelerationRate
properties to create a satisfying scroll-and-snap experience when enabled.
Notes
- The component adds a small empty view at the end of the scroll content to provide trailing padding
- Although there's an
img
prop in the component interface, it's not currently used in the implementation - The "See all" link uses Expo Router's Link component for navigation
- To ensure proper snapping behavior, make sure all cards have a consistent width
- For best performance with many items, consider using a FlatList-based version for very long lists