SwipeUI

Avatar

A round photo with an initials fallback when there's no image or it fails to load.

npx @swipeui/cli add avatar
Variant
Preset
Material
Scheme
Feel
Real free component with a browser animation bridge. Native motion, haptics and materials need a device.

When to use it

  • Showing a person in comments, chats, contact lists and profile headers.
  • Places where a photo may be missing and initials should appear instead.
  • Small, medium and large sizes across lists and headers.

When not to use it

  • Several people stacked together. Use Avatar group or Presence stack.
  • Brand or app icons; use an image.
  • Large profile hero photos. Use an image with a fixed aspect ratio.

Installation

Run this from your app's root. If SwipeUI isn't set up yet, run npx @swipeui/cli init first; it sets up Uniwind, the theme tokens and the cn helper.

npx @swipeui/cli add avatar
  • Adds components/swipeui/ui/avatar.tsx and 2 shared helpers.
  • Installs class-variance-authority, clsx, tailwind-merge. In Expo apps it uses npx expo install so versions match your SDK.

Usage

app/profile.tsx
import { Avatar } from '@/components/swipeui/ui/avatar';

<Avatar name="Ada Lovelace" source={{ uri: user.photoUrl }} />
<Avatar name="Grace Hopper" size="lg" />

The initials (up to two, from the first two words of name) show while there's no source, or when the image fails to load. A new source gets a fresh attempt. initialsOf is exported too, and handles emoji and non-Latin scripts.

Sizes are sm (32pt), md (40pt) and lg (56pt).

API reference

PropTypeDefaultDescription
namestring—

The person's name: read by screen readers and used for the initials.

status?"away" | "busy" | "offline" | "online"undefined

Optional presence indicator outside the image clip.

statusLabel?stringstatus

Translated presence label.

source?ImageSource—

The photo. While it is missing, loading fails or it is undefined, the initials show.

size?AvatarSize'md'

The diameter: sm 32pt, md 40pt, lg 56pt.

className?string—

Classes merged over the size.

style?StyleProp<ViewStyle>—

Style escape hatch for the container.

testID?string—

The container's test ID; the photo gets ${testID}-image.

Composition and behavior

  • name gives the spoken name and the initials.
  • source is the photo; size is sm (32), md (40) or lg (56 points).

Feedback lineup settings

PropDoes / default
nameThe person's name: read by screen readers and used for the initials.
statusOptional presence indicator outside the image clip. @default undefined
statusLabelTranslated presence label. @default status
sourceThe photo. While it is missing, loading fails or it is undefined, the initials show.
sizeThe diameter: sm 32pt, md 40pt, lg 56pt. @default 'md'
classNameClasses merged over the size.
styleStyle escape hatch for the container.
testIDThe container's test ID; the photo gets ${testID}-image.

Presence uses the original edge position for small/medium avatars and a proportional inset only for the large avatar. The image clip never clips the status indicator.

Behavior and gestures

  • Static; wrap it in Pressable if tapping should open a profile.
  • If the photo is missing or fails to load, initials from the name appear.

Accessibility

  • Announced as an image named after the person.
  • Initials are built from up to two words and work with emoji and non-Latin scripts.
  • Initials don't scale with text size, so they always fit the circle; the name is still read in full.

Motion

  • Static on its own; any movement comes from the parent that animates it.
  • Static.

Performance

  • Uses React Native's Image; swap to expo-image in your copy if you want disk caching.

Notes for AI

  • Always pass name, even when there's a photo.

Compatibility

Runs onSupported
Expo SDK 57Yes
Expo SDK 58Yes
React Native CLI (with Expo modules)Yes
Expo GoYes
iOSYes
AndroidYes

This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.

Related items