Avatar
A round photo with an initials fallback when there's no image or it fails to load.
npx @swipeui/cli add avatarWhen 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.tsxand 2 shared helpers. - Installs class-variance-authority, clsx, tailwind-merge. In Expo apps it uses
npx expo installso versions match your SDK.
Usage
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
| Prop | Type | Default | Description |
|---|---|---|---|
name | | — | The person's name: read by screen readers and used for the initials. |
status? | | | Optional presence indicator outside the image clip. |
statusLabel? | | | Translated presence label. |
source? | | — | The photo. While it is missing, loading fails or it is undefined, the initials show. |
size? | | | The diameter: |
className? | | — | Classes merged over the size. |
style? | | — | Style escape hatch for the container. |
testID? | | — | The container's test ID; the photo gets |
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
| Prop | Does / default |
|---|---|
name | The person's name: read by screen readers and used for the initials. |
status | Optional presence indicator outside the image clip. @default undefined |
statusLabel | Translated presence label. @default status |
source | The photo. While it is missing, loading fails or it is undefined, the initials show. |
size | The diameter: sm 32pt, md 40pt, lg 56pt. @default 'md' |
className | Classes merged over the size. |
style | Style escape hatch for the container. |
testID | The 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 on | Supported |
|---|---|
| Expo SDK 57 | Yes |
| Expo SDK 58 | Yes |
| React Native CLI (with Expo modules) | Yes |
| Expo Go | Yes |
| iOS | Yes |
| Android | Yes |
This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.