Icon Component

A versatile icon component for React Native applications that provides consistent icon rendering with touch interactions and customizable styling options.

Features

  • 🎨 Flexible Styling - Customizable size, color, and styling options
  • 👆 Touch Interactions - Built-in press and long press support
  • 🎯 Hit Area - Configurable touch target area for better usability
  • 🖼️ Image Support - Works with any React Native image source
  • 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 { Icon } from 'rn-base-component'

export default function App() {
  return 
}

Interactive Icon

⚛️TSX
 console.log('Heart icon pressed!')}
/>

Advanced Usage

Custom Size and Color

⚛️TSX

With Touch Feedback

⚛️TSX

Custom Hit Area

⚛️TSX

Using with Vector Icons

⚛️TSX
import MaterialIcons from 'react-native-vector-icons/MaterialIcons'

}
  onPress={handleHome}
/>

API Reference

IconProps

PropTypeDefaultDescription
sourceImageSourcePropTypeRequired*Image source for the icon
componentReact.ReactNodeRequired*Custom component (alternative to source)
sizenumber24Size of the icon
tintColorstringundefinedColor tint for the icon
onPress() => voidundefinedPress handler
onLongPress() => voidundefinedLong press handler
hitSlopInsetsundefinedHit area extension
hitAreaSizenumberundefinedSquare hit area size
disabledbooleanfalseDisable interactions
styleStyleProp<ViewStyle>undefinedCustom container style
imageStyleStyleProp<ImageStyle>undefinedCustom image style
testIDstringundefinedTest identifier

Source vs Component

Use either source for image-based icons or component for custom React components (like vector icons). Both props are mutually exclusive.

Icon Collections

⚛️TSX
import React from 'react'
import { View } from 'react-native'
import { Icon } from 'rn-base-component'

export default function NavigationBar() {
  return (
    
       navigate('Home')}
      />
      
       navigate('Search')}
      />
      
       navigate('Profile')}
      />
      
       navigate('Settings')}
      />
    
  )
}

const styles = StyleSheet.create({
  navigationBar: {
    flexDirection: 'row',
    justifyContent: 'space-around',
    paddingVertical: 12,
    backgroundColor: '#ffffff',
    borderTopWidth: 1,
    borderTopColor: '#e0e0e0',
  },
})

Action Icons

⚛️TSX

  
  
  
  
  

Status Icons

⚛️TSX

  
  Completed



  
  Warning

Integration with Vector Icon Libraries

React Native Vector Icons

⚛️TSX
import React from 'react'
import { Icon } from 'rn-base-component'
import MaterialIcons from 'react-native-vector-icons/MaterialIcons'
import Ionicons from 'react-native-vector-icons/Ionicons'

export default function VectorIconsExample() {
  return (
    
      }
        onPress={handleFavorite}
      />
      
      }
        onPress={handleSettings}
      />
    
  )
}

Custom SVG Icons

⚛️TSX
import React from 'react'
import { Icon } from 'rn-base-component'
import Svg, { Path } from 'react-native-svg'

const CustomSVGIcon = ({ size = 24, color = '#000' }) => (
  
    
  
)

export default function SVGIconExample() {
  return (
    }
      onPress={handleSecuritySettings}
    />
  )
}

Common Use Cases

Button with Icon

⚛️TSX
import React from 'react'
import { TouchableOpacity, Text, View } from 'react-native'
import { Icon } from 'rn-base-component'

export default function IconButton({ onPress, title, iconSource }) {
  return (
    
      
      {title}
    
  )
}

const styles = StyleSheet.create({
  button: {
    flexDirection: 'row',
    alignItems: 'center',
    backgroundColor: '#007AFF',
    paddingHorizontal: 16,
    paddingVertical: 12,
    borderRadius: 8,
  },
  buttonIcon: {
    marginRight: 8,
  },
  buttonText: {
    color: '#ffffff',
    fontSize: 16,
    fontWeight: '600',
  },
})

Icon with Badge

⚛️TSX

  
  {unreadCount > 0 && (
    
      {unreadCount}
    
  )}


const styles = StyleSheet.create({
  iconContainer: {
    position: 'relative',
  },
  badge: {
    position: 'absolute',
    top: -8,
    right: -8,
    backgroundColor: '#FF6B6B',
    borderRadius: 12,
    minWidth: 24,
    height: 24,
    justifyContent: 'center',
    alignItems: 'center',
  },
  badgeText: {
    color: '#ffffff',
    fontSize: 12,
    fontWeight: 'bold',
  },
})

Loading States

⚛️TSX
import React, { useState } from 'react'
import { ActivityIndicator } from 'react-native'
import { Icon } from 'rn-base-component'

export default function LoadingIcon({ isLoading, onPress }) {
  return (
    
      {isLoading ? (
        
      ) : (
        
      )}
    
  )
}

Best Practices

  1. Consistent Sizing - Use standardized icon sizes (16, 20, 24, 32px)
  2. Adequate Touch Targets - Ensure minimum 44px touch area for interactive icons
  3. Meaningful Icons - Use universally recognized icons for common actions
  4. Color Consistency - Maintain consistent color scheme across icon usage
  5. Accessibility - Provide proper accessibility labels for interactive icons
  6. Performance - Optimize icon assets for different screen densities
  7. Vector Icons - Prefer vector icons for scalability and crisp rendering

Touch Targets

Always ensure interactive icons have adequate touch targets (minimum 44px) for better usability, especially on mobile devices.

Asset Optimization

For image-based icons, provide multiple resolutions (@1x, @2x, @3x) to ensure crisp rendering on all devices.