Skip to main content

CamoAvatar

Concept​

1. Why​

Avatars represent a person or entity with a photo, initials or an icon, in lists, top bars, chips and comments. Fluent has Avatar and Persona. Material and Apple don't have a named component but use avatars everywhere. Getting the fallbacks right (a broken image shows initials, and initials get a stable color) is exactly the boilerplate apps repeat.

2. Shape​

Material mapping preview: there's no M3 component. The Material skin draws:

  • a circle;
  • initials in titleMedium;
  • a background picked from the brand/tone containers by a hash of the name;
  • sizes S 24, M 40, L 56.

3. API​

Contract​

fun CamoAvatar(
name: String? = null, // used for initials, color and the accessible name
image: Widget? = null, // the app's image widget (Coil/Kamel AsyncImage, Flutter Image), loaded by the app
size: AvatarSize = Medium, // Small | Medium | Large (or a custom Dp via the theme)
shape: AvatarShape? = null, // null → AvatarTheme.shape; Circle | Rounded | Square
presence: Presence? = null, // Online | Away | Busy | Offline → a small status dot
)
fun CamoAvatarGroup(avatars: List<Widget>, max: Int = 3) // overlapping stack with "+N"

The image is a widget (the same rule as icons, ADR-12): the app passes its own image-loading widget. Core doesn't depend on an image library. If the image fails or is null, the initials show.

State → renderer: AvatarState(initials?, colorSeed, size, shape, presence?). Slots: AvatarSlots(image?).

Tokens used​

  • brand/status container colors for the initials background, and their on-colors
  • typography.labelLarge (S), titleMedium (M), titleLarge (L)
  • shapes.full (Circle), AvatarTheme.roundedShape (Rounded, default shapes.small), shapes.none (Square)
  • success/warning/error/outline for the presence dot

Component theme​

theme.components.avatar: AvatarTheme?. Every field is nullable in the theme. The skin's defaults(theme) fills whatever isn't set (Material defaults shown). See Theme §3.10.

FieldTypeMaterial defaultWhat it's for
shapeAvatarShapeCirclethe avatar shape for the whole brand (ADR-28; Carbon: Square)
roundedShapeShapeshapes.smallcorners of Rounded avatars
sizeSmall / sizeMedium / sizeLargeDp24 / 40 / 56sizes
initialsPaletteList of color pairsthe 5 container families (primary, secondary, tertiary, info, success)backgrounds picked by a stable hash of name
presenceSizeDp10status dot
groupOverlapDp8overlap in groups

Accessibility​

  • The accessible name is name ("Dwiki Riyadi"), plus the presence ("online") when set. With no name, it's decorative.
  • In lists, the avatar merges into the row (the row already says the name, so the avatar is decorative there, which the list item handles).

4. Build steps​

  1. Initials extraction (first letters of the first and last words; handles single words and emoji safely), a stable color hash, the presence dot.
  2. CamoAvatar, CamoAvatarGroup, and the renderers.
  3. Tests: "Dwiki Riyadi" → "DR"; the same name always gets the same color; a failed image shows the initials; "+2" for 5 avatars with max 3.

Done when

  • A contacts list with photos, initials and presence renders identically on every platform.

5. Edge cases​

CaseDecided behavior
Names in non-Latin scripts (CJK, Arabic)The first grapheme of the name. No two-letter split for scripts without word spaces.
Emoji or empty namesThe icon fallback.
Image loading stateThe initials show until the image widget reports success. The app's image widget decides the placeholder behavior.
Changed in the M7 build (2026-10-28)
  • AvatarTheme gains textStyleSmall / Medium / Large, neutralColors (the person icon and a group's "+N"), presenceColors (one per presence, plus the ring), ringWidth, personIcon and strings (the presence words, "2 more").
  • AvatarState.colorSeed is the 32-bit FNV-1a hash of the name's UTF-8 bytes, null for the icon and the "+N"; both libraries test the same vectors ("Dwiki Riyadi" → 0xCDC853E9).
  • Initials need a letter: a name that starts with an emoji, a digit or a symbol gets the icon. Both platforms split graphemes with the same small rules (combining marks, variation selectors, skin tones, zero-width joins, flags).
  • In a CamoListItem's leading slot the avatar is decorative: the list item marks its slot, so the row says the name once.
  • CamoAvatarGroup gains size (for the "+N").
  • Minimal: neutral circles, 24 / 36 / 48. Fluent: brand-tinted initials, 24 / 32 / 48.

Implementation​

1. Why​

Avatars show an image, or initials when there's no image or it fails. Core doesn't depend on an image library (ADR-12), so the app passes its own image composable (Coil 3's AsyncImage is multiplatform). Kotlin's trick for the fallback: draw the initials underneath and the image on top, so a missing or failed image simply leaves the initials visible.

2. Shape​

3. API​

@Composable
public fun CamoAvatar(
modifier: Modifier = Modifier,
name: String? = null,
image: (@Composable () -> Unit)? = null, // e.g. { AsyncImage(url, contentDescription = null, contentScale = ContentScale.Crop) }
size: AvatarSize = AvatarSize.Medium,
shape: AvatarShape? = null, // null → AvatarTheme.shape
presence: Presence? = null,
)

@Composable public fun CamoAvatarGroup(avatars: List<@Composable () -> Unit>, modifier: Modifier = Modifier, max: Int = 3)
  • Initials: the first grapheme of the first and last words of name ("Dwiki Riyadi" → "DR"), uppercased with the locale. Graphemes, not chars, so emoji and combined characters stay whole (a small BreakIterator-free splitter in core, since java.text isn't in common code).
  • Color: picked from style.initialsPalette by a stable FNV-1a hash of name, the same on every platform (not String.hashCode(), which isn't guaranteed identical across Kotlin targets).
  • Clipping: Modifier.clip(shape) on the stack; the presence dot is placed outside the clip with a surface-colored ring.
  • Semantics: the avatar is one node with contentDescription = name (plus presence, "Dwiki Riyadi, online"); the image composable's own description is cleared.
  • Group: a Row with negative spacing -style.groupOverlap, each avatar with a ring, and a "+N" avatar for the rest.

4. Build steps​

  1. AvatarTheme / Style (with shape, roundedShape), CamoAvatar, CamoAvatarGroup, the DebugSkin renderer.
  2. commonTest: initials for one word, two words, emoji names; the same color for the same name on JVM and native tests; a null image shows initials; presence in the description; the "+N" count.

Done when

  • A contact list with photos, broken URLs and no photos looks right in every shape, and each row announces the person once.

5. Edge cases​

CaseDecided behavior
Image loading slowlyInitials show until the image paints over them (no flicker to blank).
No name and no imageA generic person icon from the skin.
Transparent PNGInitials show through; apps with transparent logos set a background in their image composable.
Changed in the M7 build (2026-10-28)
  • avatarInitials(name) and avatarColorSeed(name): UInt are public; AvatarStyle.colorsFor(state), sizeOf, textStyleOf and shapeOf resolve the rest.
  • The list item marks its leading slot with an internal composition local; the avatar then sets no description.