@umituz/react-native-avatar
v1.1.0
Published
User avatar components for React Native apps - image, initials, icon support, status indicators, avatar groups
Maintainers
Readme
@umituz/react-native-avatar
User avatar components for React Native apps - image, initials, icon support, status indicators, avatar groups.
Features
- ✅ Image Avatars - Display user profile images with fallback
- ✅ Initials Generation - Automatic initials from names (Turkish character support)
- ✅ Icon Placeholders - Fallback to icons when no image/name
- ✅ Status Indicators - Online/offline/away/busy status badges
- ✅ Avatar Groups - Stacked layout with overflow count (+N)
- ✅ Consistent Colors - Same name always gets same color
- ✅ Multiple Sizes - xs, sm, md, lg, xl, xxl
- ✅ Multiple Shapes - Circle, square, rounded
- ✅ Type-Safe - Full TypeScript support
Installation
npm install @umituz/react-native-avatarPeer Dependencies
npm install @umituz/react-native-design-system @umituz/react-native-design-system-themeUsage
Basic Avatar
import { Avatar } from '@umituz/react-native-avatar';
// Image avatar
<Avatar
uri="https://example.com/avatar.jpg"
name="Ümit Uz"
size="lg"
shape="circle"
/>
// Initials avatar (no image)
<Avatar name="Ümit Uz" size="md" />
// Shows: ÜU
// Icon avatar (fallback)
<Avatar size="sm" />Avatar with Status
<Avatar
name="John Doe"
showStatus
status="online"
size="md"
/>Avatar Group
import { AvatarGroup } from '@umituz/react-native-avatar';
const users = [
{ name: 'Ümit Uz', uri: 'https://...' },
{ name: 'John Doe', uri: 'https://...' },
{ name: 'Jane Smith' },
{ name: 'Bob Johnson' },
{ name: 'Alice Brown' },
];
// Show 3 avatars + overflow
<AvatarGroup items={users} maxVisible={3} />
// Shows: [Avatar] [Avatar] [Avatar] [+2]Avatar Utilities
import { AvatarUtils, AVATAR_COLORS } from '@umituz/react-native-avatar';
// Generate initials
const initials = AvatarUtils.generateInitials('Ümit Uz'); // ÜU
const emailInitials = AvatarUtils.generateInitialsFromEmail('[email protected]'); // UE
// Get consistent color
const color = AvatarUtils.getColorForName('Ümit Uz'); // Always same color
// Get size config
const config = AvatarUtils.getSizeConfig('lg');
// Returns: { size: 56, fontSize: 18, iconSize: 28, statusSize: 12, borderWidth: 2 }useAvatar Hook
import { useAvatar } from '@umituz/react-native-avatar';
const { isLoading, hasError, onLoad, onError, generateInitials } = useAvatar();
<Image
source={{ uri }}
onLoad={onLoad}
onError={onError}
/>
{hasError && <Text>{generateInitials(name)}</Text>}API Reference
Avatar
Avatar component with automatic fallback hierarchy.
Props:
uri?: string- Image URIname?: string- User name for initialsicon?: string- Icon name (fallback)size?: AvatarSize- Size preset (default: 'md')shape?: AvatarShape- Shape (default: 'circle')backgroundColor?: string- Custom background colorshowStatus?: boolean- Show status indicatorstatus?: 'online' | 'offline' | 'away' | 'busy'- Statusstyle?: ViewStyle- Custom container styleimageStyle?: ImageStyle- Custom image styleonPress?: () => void- OnPress handler
Fallback Hierarchy:
- Image (if
uriprovided) - Initials (if
nameprovided) - Icon (fallback)
AvatarGroup
Avatar group component with overflow count.
Props:
items: AvatarGroupItem[]- Array of avatar itemsmaxVisible?: number- Maximum visible avatars (default: 3)size?: AvatarSize- Avatar size (default: 'md')shape?: AvatarShape- Avatar shape (default: 'circle')spacing?: number- Spacing between avatars (default: -8 for overlap)style?: ViewStyle- Custom container style
useAvatar()
React hook for avatar state management.
Returns:
isLoading: boolean- Image loading statehasError: boolean- Image error stateonLoad: () => void- Handle image load successonError: () => void- Handle image load errorreset: () => void- Reset stategenerateInitials: (name: string) => string- Generate initialsgetColorForName: (name: string) => string- Get consistent color
AvatarUtils
Utility class for avatar operations.
Methods:
generateInitials(name: string): string- Generate initials from namegenerateInitialsFromEmail(email: string): string- Generate initials from emailgetColorForName(name: string): string- Get consistent color for namegetSizeConfig(size: AvatarSize): SizeConfig- Get size configurationgetBorderRadius(shape: AvatarShape, size: number): number- Get border radiusgetStatusColor(status: 'online' | 'offline' | 'away' | 'busy'): string- Get status colorvalidateConfig(config: Partial<AvatarConfig>): AvatarConfig- Validate confighasImage(config: AvatarConfig): boolean- Check if has imagehasInitials(config: AvatarConfig): boolean- Check if has initialshasIcon(config: AvatarConfig): boolean- Check if has icon
Types
AvatarSize- 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl'AvatarShape- 'circle' | 'square' | 'rounded'AvatarType- 'image' | 'initials' | 'icon'AvatarConfig- Avatar configuration interfaceSizeConfig- Size configuration interfaceAvatarGroupConfig- Avatar group configuration interfaceAvatarGroupItem- Avatar item for group
Constants
SIZE_CONFIGS- Size configurations for all sizesAVATAR_COLORS- Array of 10 vibrant colors for avatarsSTATUS_COLORS- Status indicator colorsSHAPE_CONFIGS- Border radius configurationsAVATAR_CONSTANTS- Default values and constants
Size Presets
xs- 24px (fontSize: 10, iconSize: 12, statusSize: 6)sm- 32px (fontSize: 12, iconSize: 16, statusSize: 8)md- 40px (fontSize: 14, iconSize: 20, statusSize: 10) - Defaultlg- 56px (fontSize: 18, iconSize: 28, statusSize: 12)xl- 80px (fontSize: 24, iconSize: 40, statusSize: 16)xxl- 120px (fontSize: 36, iconSize: 60, statusSize: 20)
Turkish Character Support
The package fully supports Turkish characters in initials generation:
AvatarUtils.generateInitials('Ümit Uz'); // ÜU
AvatarUtils.generateInitials('Şahin Yılmaz'); // ŞY
AvatarUtils.generateInitials('Özgür Çelik'); // ÖÇLicense
MIT
Author
Ümit UZ [email protected]
