Card Component

A flexible and reusable card container component for React Native applications that provides a consistent layout foundation with optional touch interactions.

Features

  • šŸŽØ Themed Styling - Consistent styling that integrates with the design system
  • šŸ‘† Touch Interactions - Optional onPress functionality with appropriate feedback
  • šŸ”§ Flexible Layout - Accepts any children for maximum flexibility
  • šŸ“± Responsive Design - Adapts to different screen sizes
  • ♿ Accessibility Ready - Built-in accessibility features
  • šŸŽÆ TypeScript Support - Full type safety and IntelliSense

Installation

šŸ’»Bash
npm install rn-base-component
# or
yarn add rn-base-component

Basic Usage

āš›ļøTSX
import React from 'react'
import { Card } from 'rn-base-component'
import { Text, View } from 'react-native'

export default function App() {
  return (
    
      This is a simple card
    
  )
}

Interactive Card

āš›ļøTSX
 console.log('Card pressed!')}>
  Tap this card

Advanced Usage

Custom Styled Card

āš›ļøTSX

  Card with custom shadow


const styles = StyleSheet.create({
  customCard: {
    margin: 16,
    shadowColor: '#000',
    shadowOffset: { width: 0, height: 2 },
    shadowOpacity: 0.1,
    shadowRadius: 4,
    elevation: 3,
  },
})

Card with Complex Content

āš›ļøTSX
 navigateToDetails()}>
  
    
    
      John Doe
      Software Engineer
      Last active 2 hours ago
    
    
  

API Reference

CardProps

PropTypeDefaultDescription
onPress() => voidundefinedCallback function when card is pressed
styleStyleProp<ViewStyle> | Array<StyleProp<ViewStyle>>undefinedCustom styles for the card
childrenReact.ReactNodeRequiredContent to be rendered inside the card

Default Styling

The Card component comes with default styling from the theme:

  • Padding: theme.spacing.slim (internal padding)
  • Border Radius: metrics.borderRadius
  • Background Color: theme.colors.cardBackground
  • Touch Opacity: Low opacity when pressable, none when not pressable

Layout Patterns

Profile Card

āš›ļøTSX

  
    
    {userName}
    {userRole}
    
      Follow
    
  

Statistics Card

āš›ļøTSX

  {value}
  {label}
  ↗ +12% from last month

Article Card

āš›ļøTSX
 openArticle(article.id)} style={styles.articleCard}>
  
  
    {article.title}
    {article.excerpt}
    
      {article.date}
      Read More
    
  

Best Practices

  1. Touch Feedback - Only add onPress when the card should be interactive
  2. Content Hierarchy - Use consistent padding and spacing inside cards
  3. Visual Consistency - Maintain consistent card styling across the app
  4. Performance - Use StyleSheet.create() for static styles
  5. Accessibility - Provide appropriate accessibility props for interactive cards
  6. Shadow Consistency - Use consistent shadow/elevation values

Performance

Cards with images should implement proper image loading and caching. For long lists, consider using FlatList with Card components.