suiss/uim · React Native Component

Avatar

A round image for a person or entity, with initials or an icon as a fallback.

Avatar is an open-source mobile component from suiss/uim for React Native and Expo, with SwiftUI and Jetpack Compose versions built from the same design tokens. The @esuiss/uim CLI copies its source into your project, so you own the code.

iOS
Avatar on iOS in light mode

Avatar is a round View that holds an AvatarImage and an AvatarFallback. The image stays hidden until it loads, and the fallback is shown while it loads or if it fails. Four sizes are available: sm, default, lg and xl; the fallback text, icons and badge scale with the size.

AvatarBadge adds a small status dot in the bottom-end corner, and AvatarGroup overlaps several avatars with an outline between them, with AvatarGroupCount for the remaining number.

Installation

$ pnpm dlx @esuiss/uim@latest add avatar

The CLI also adds what it builds on: Icon, Text.

Manual

  1. Install the dependencies:
npx expo install cn
  1. Add the pieces it builds on: Icon, Text, and the primitives components/primitives/avatar.tsx, components/primitives/use-render.tsx.

  2. Copy the source into components/ui/avatar.tsx:

uniwind/components/ui/avatar.tsx
import { cn } from "cn"
import * as React from "react"
import { View } from "react-native"
import * as AvatarPrimitive from "@/components/primitives/avatar"
import { resolveClassName } from "@/components/primitives/use-render"
import { IconClassContext } from "@/components/ui/icon"
import { Text, TextClassContext } from "@/components/ui/text"

type AvatarSize = "default" | "sm" | "lg" | "xl"

const AvatarSizeContext = React.createContext<AvatarSize>("default")

const AvatarGroupItemContext = React.createContext<number | null>(null)

const ROOT_SIZE: Record<AvatarSize, string> = {
  sm: "size-6",
  1. Update the import paths to match your project.

Usage

import { Avatar, AvatarImage, AvatarFallback, AvatarBadge, AvatarGroup, AvatarGroupCount } from "@/components/ui/avatar"
<Avatar>
  <AvatarImage
    alt="Ada Lovelace"
    source={{ uri: "https://i.pravatar.cc/150?img=5" }}
  />
  <AvatarFallback>
    <Text>AL</Text>
  </AvatarFallback>
</Avatar>

Give AvatarImage a source and an alt. Put initials or an Icon in AvatarFallback; plain strings are wrapped in Text. Use delay on the fallback to avoid a flash on fast connections, and onLoadingStatusChange on the image to react to loading.

Set size on each Avatar, and pass the same size to AvatarGroupCount. On the sm size, the badge hides its children and shows a plain dot.

Examples

Fallback

Initials shown when there is no image.

iOS
Avatar (fallback) on iOS in light mode

Sizes

The sm, default, lg and xl sizes.

iOS
Avatar (sizes) on iOS in light mode

Group

Overlapping avatars in an AvatarGroup with a count.

iOS
Avatar (group) on iOS in light mode

With badge

A check badge at each size.

iOS
Avatar (with badge) on iOS in light mode

API Reference

Avatar

Round container that sets the size.

ExtendsReact.ComponentProps<typeof AvatarPrimitive.Root>
PropType
About
sm, default, lg or xl.
Type
AvatarSize
Default
"default"

AvatarImage

Image that appears once it has loaded.

ExtendsReact.ComponentProps<typeof AvatarPrimitive.Image>

AvatarFallback

Initials or icon shown while the image is missing.

ExtendsReact.ComponentProps<typeof AvatarPrimitive.Fallback>

AvatarBadge

Status dot in the bottom-end corner.

ExtendsReact.ComponentProps<typeof View>React.RefAttributes<View>

AvatarGroup

Row that overlaps its avatars.

ExtendsReact.ComponentProps<typeof View>React.RefAttributes<View>

AvatarGroupCount

Round counter for the remaining items in a group.

ExtendsReact.ComponentProps<typeof View>React.RefAttributes<View>
PropType
About
Matches the size of the avatars in the group.
Type
AvatarSize
Default
"default"

Accessibility

  • AvatarImage uses alt as its accessibilityLabel.
  • The image is hidden from screen readers until it has loaded.
  • The badge has no label; describe the status in nearby text if it matters.

Notes

  • Uses bg-label-secondary, bg-accent, bg-surface-secondary and border-surface tokens; the fallback is softer in dark mode.
  • Light and dark follow the system appearance.