CustomCard
A highly customizable card component with support for background images, shadows, borders, and more.
CustomCard
The CustomCard component provides a versatile container with various customization options for creating cards with different styling. It supports background images, shadows, borders, and interactive behavior.
Features
- Multiple Rounded Styles: Choose from various border radius options
- Customizable Padding: Control internal spacing
- Shadow Options: Apply different shadow levels with platform-specific handling
- Border Support: Optional borders with customizable color
- Background Image: Support for image backgrounds with overlay options
- Navigation Support: Built-in href prop for navigation
- Horizontal Layout: Optional horizontal orientation
- Theming Support: Automatically adapts to light/dark mode
Import
Props
Prop | Type | Default | Description |
---|---|---|---|
rounded | 'none' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | 'full' | 'lg' | Border radius of the card |
padding | 'none' | 'sm' | 'md' | 'lg' | 'xl' | 'md' | Internal padding of the card |
shadow | 'none' | 'sm' | 'md' | 'lg' | 'xl' | 'none' | Shadow intensity |
border | boolean | false | Whether to show a border |
borderColor | string | — | Custom border color (if not set, uses theme-based color) |
background | boolean | true | Whether to show background color |
elevation | boolean | true | Whether to apply elevation (shadow on Android) |
className | string | '' | Additional Tailwind classes |
style | ViewStyle | — | Additional style object |
backgroundImage | string | — | URL for background image |
backgroundImageStyle | ViewStyle | — | Style for background image |
overlayColor | string | 'black' | Color of overlay on background image |
overlayOpacity | number | 0.3 | Opacity of overlay (0-1) |
horizontal | boolean | false | Whether to layout children horizontally |
onPress | () => void | — | Function to call when card is pressed |
href | string | — | Navigation link for the card |
children | ReactNode | Required | Content to display inside the card |
Usage Examples
Basic Card
Styled Card
Card with Background Image
Interactive Card
Navigation Card
Horizontal Card
Card Showcase
Profile Card
Product Card
Featured Article Card
Settings Card
Card Variants
Shadow Variants
Rounded Variants
Best Practices
Consistent Card Styling
Use consistent card styling throughout your application:
Background Image Best Practices
When using background images, ensure text remains readable:
Interactive Cards
Use visual cues to indicate interactivity:
Implementation Details
The CustomCard component is built using React Native's View and ImageBackground components. It uses Tailwind CSS classes for styling, with dynamic class generation based on the provided props.
For background images, the component uses React Native's ImageBackground with an optional overlay. The overlay is implemented using a View with absolute positioning and customizable color and opacity.
The component handles platform-specific shadow implementation, using shadow utilities for iOS and elevation for Android. This ensures consistent appearance across platforms.
For interactive cards, the component wraps the content in either a TouchableOpacity (for onPress) or a Link component from Expo Router (for href), making it easy to create clickable cards.
Notes
- Shadow implementation differs between iOS and Android due to platform differences
- When using background images, ensure they are properly loaded and cached for optimal performance
- For navigation cards using the href prop, make sure the target route exists in your navigation structure
- The component automatically handles light/dark mode through Tailwind's dark mode classes
- On Android, shadow is implemented using elevation, which affects z-index ordering