# Draw: Discord's User Profile Status Indicator

> Recreating Discord's cut-out status badge on a profile picture using Canvas.

**Date:** 2026-10-15T00:00:00.000Z
**Tags:** Draw, Canvas, Animation

## What we're building

A circular profile photo with a colored dot in the corner. Simple enough
to fake with `Modifier.clip(CircleShape)` and a `Box` stacked on top. The
part that fakery can't reach is the thin ring of background visible
*around* the dot, between it and the photo's edge, because that ring has
to show whatever's actually behind the avatar, not a hardcoded color.

Full source: [`DiscordAvatarScreen.kt`](https://github.com/rifqimfahmi/recomposed.blog-demo/blob/main/app/src/main/java/blog/recomposed/demosrecomposed/ui/screens/DiscordAvatarScreen.kt).

## The intuition

* Rounding the photo and badging it with a status dot are usually treated
  as two separate problems: one is clipping, the other is "draw a circle
  on top." They're actually the same operation applied twice: **erase
  pixels from the photo**, not paint over them.
* A solid circle drawn on top of the photo would hide it, sure, but only
  with the circle's own flat color. The gap around Discord's dot isn't a
  color, it's a hole, the card's real background (a `Zinc800` box here,
  anything in the real app) showing through undisturbed.
* Getting a hole instead of a colored patch means the corner-rounding and
  the badge cutout both have to go through the same mechanism: erase,
  composited correctly, then paint the dot back into the hole.

- [BlendMode vs CompositingStrategy: It's Not a Fence, It's a Different Canvas](/blend-mode-and-compositing-strategy#where-isolation-isnt-optional-blend-modes-that-erase) — The isolation + BlendMode.Clear mechanism this post's cutout badge runs on, including the exact 'spotlight / cutout-badge' case this post builds.

- [animate\*AsState vs Animatable: Animation Is Just an Interpolated Value](/compose-value-based-animation#more-cases-animatable-is-the-same-mechanism-by-hand) — Why calling Animatable.animateTo directly, instead of animate\*AsState, is what lets Step 4's three radii stage in sequence: each call is a suspend function you can await.

## Step 1: Rounding the photo without `clip()`

```kotlin
val fullRect = Path().apply {
    addRect(Rect(topLeft = Offset(0f, 0f), bottomRight = Offset(size.width, size.height)))
}

val innerCircle = Path().apply {
    addOval(Rect(center = Offset(size.width / 2f, size.height / 2f), radius = size.minDimension / 2))
}

// XOR of the full square and the inner circle leaves just the four
// corners outside the circle, which get cleared below to round the image.
val cornerPath = Path.combine(
    operation = PathOperation.Xor,
    path1 = fullRect,
    path2 = innerCircle
)
```

`Modifier.clip(CircleShape)` would round the photo in one line, and
normally that's the right call. It's not wrong here either, it's just
incomplete: clipping only handles the corners.

The badge hole still needs its own `BlendMode.Clear` inside an
`Offscreen` layer, regardless of how the corners get rounded. A clip's
canvas-stack stencil has no way to reveal whatever's actually sitting
behind the avatar, only `Clear` can do that.

Building `cornerPath` as an explicit shape means one `Offscreen` layer
and one set of `Clear` calls handle both exclusions, corners and badge.
The alternative, pairing `clip()` for the corners with a second
offscreen pass for the badge, sets up the same offscreen machinery
twice.

`PathOperation.Xor` keeps whatever's in exactly one of the two paths.
Since `innerCircle` sits entirely inside `fullRect`, that leaves only the
four corners, the square minus the circle.

This is a path boolean operation, combining two shapes into a new one.
It's not the `BlendMode.Xor` pixel formula from the fundamentals post
above, same name, different layer of the API.

```kotlin
AsyncImage(
    modifier = Modifier
        .fillMaxSize()
        .graphicsLayer {
            compositingStrategy = CompositingStrategy.Offscreen
        }
        .drawWithCache {
            // ...cornerPath built here, see above...
            onDrawWithContent {
                drawContent()
                drawPath(path = cornerPath, color = Color.Transparent, blendMode = BlendMode.Clear)
            }
        },
    model = "...",
    contentDescription = "User profile photo",
    contentScale = ContentScale.Crop,
)
```

`BlendMode.Clear` erases `dst` (The destination pixel: whatever color is already sitting at a given spot before your draw call blends a new src pixel into it.) wherever `src` is drawn. The color you
pass in doesn't matter, it's ignored entirely.

What `dst` actually refers to depends on where this runs:

* **Without `CompositingStrategy.Offscreen`**, `dst` is the real screen.
  `Clear` punches a hole through everything already painted below it in
  the whole frame.
* **With `Offscreen`**, `dst` is this subtree's own private buffer, the
  photo and nothing else. `Clear` only erases pixels the photo itself
  drew.

## Step 2: Punching the badge hole, not painting over it

```kotlin
// Bottom-right corner, where the status badge sits.
val indicatorCenterOffset = Offset(
    x = size.width - StatusIndicatorOuterRadius.toPx(),
    y = size.height - StatusIndicatorOuterRadius.toPx()
)
// Punches a hole in the avatar so the badge isn't drawn over the photo.
val indicatorCutoutCircle = Path().apply {
    addOval(Rect(center = indicatorCenterOffset, radius = StatusIndicatorOuterRadius.toPx()))
}
```

Same reasoning as the corners: one more `Clear` draw, in the same
offscreen buffer, this time a circle sized to the *outer* radius (badge
plus gap).

Reusing the buffer matters. Whatever shows through this hole is whatever
the real app draws behind the avatar at runtime, a themed container, a
list row, anything. An opaque circle drawn on top couldn't do that, it
would only ever show its own fill color, baked in at draw time
regardless of what's actually behind it.

> **Order inside the buffer**
>
> Both `Clear` draws and the dot draw below all happen inside the same
> `onDrawWithContent` block, so they run in call order: photo first, then
> corners cleared, then the badge hole cleared, then the dot painted back
> in. Reordering the dot draw before the hole-clear would erase the dot
> along with everything else.

## Step 3: Drawing the dot back into the hole

```kotlin
// The visible status badge, drawn inside the cutout hole.
val indicatorDotCircle = Path().apply {
    addOval(Rect(center = indicatorCenterOffset, radius = StatusIndicatorInnerRadius.toPx()))
}

onDrawWithContent {
    drawContent()
    drawPath(path = cornerPath, color = Color.Transparent, blendMode = BlendMode.Clear)
    drawPath(path = indicatorCutoutCircle, color = Color.Transparent, blendMode = BlendMode.Clear)
    drawPath(path = indicatorDotCircle, color = status.color)
}
```

The dot uses the *inner* radius, smaller than the hole it's sitting in.
That gap between the two radii is exactly what leaves the visible ring
of real background between the dot and the photo's edge.

`status.color` comes from a sealed `Status` class (`Online`, `Away`,
`Offline`). The dot's color is just a normal draw, no blend mode needed,
it's opaque paint landing on an already-transparent hole.

## Step 4: Staging the reveal with three `Animatable`s

[Video](/posts/draw-discord-profile-status/demo.mp4)

*Three Animatables, driven in sequence: the photo's circle grows in first, then the badge ring, then the dot.*

```kotlin
val avatarAnimatable = remember { Animatable(0f) }
val bigRadiusAnimatable = remember { Animatable(0f) }
val smallRadiusAnimatable = remember { Animatable(0f) }

LaunchedEffect(avatarSize) {
    if (avatarSize == Size.Unspecified) return@LaunchedEffect
    delay(1200.milliseconds)

    // Reset so re-entering this LaunchedEffect (avatarSize changing again) replays cleanly.
    avatarAnimatable.snapTo(0f)
    bigRadiusAnimatable.snapTo(0f)
    smallRadiusAnimatable.snapTo(0f)

    avatarAnimatable.animateTo(avatarSize.minDimension / 2, animationSpec = spring())
    bigRadiusAnimatable.animateTo(StatusIndicatorOuterRadius.toPx(), animationSpec = spring())
    smallRadiusAnimatable.animateTo(StatusIndicatorInnerRadius.toPx(), animationSpec = spring())
}
```

Each of these three radii, the photo's own clip circle, the badge hole,
the dot, feeds straight into the exact same paths built in the previous
steps. Only the values change, from fixed constants to animated ones.

Sequencing three separate `Animatable`s by calling `animateTo` one after
another works because each call suspends until its spring settles. The
next line doesn't start animating until the previous one finishes. No
`Transition`, no manual delay math between stages, just plain sequential
suspending calls.

## Variations and tradeoffs

* **`Xor` vs `Difference` for the corner path.** `innerCircle` is fully
  contained inside `fullRect` here, so `PathOperation.Xor` and
  `PathOperation.Difference` produce an identical `cornerPath`. `Xor`
  reads as "whatever's in exactly one of these," `Difference` reads as
  "this minus that," which matches the actual intent (remove the circle
  from the square) more directly. Reach for `Difference` when one path
  is always meant to be a strict subset of the other, and save `Xor` for
  cases where neither path fully contains the other.
* **`Offscreen` isn't free.** Every avatar using this technique allocates
  its own offscreen buffer. Fine for a single profile header, worth
  checking if this ever ends up inside a long list of avatars, where
  dozens of offscreen buffers per frame is a different cost profile than
  one.
* **The gap ring is just a radius difference.** `StatusIndicatorOuterRadius`
  minus `StatusIndicatorInnerRadius` is the whole gap. Widening or
  removing that ring, say, to match a design with no visible gap at all,
  is a one-line change to those two constants, nothing about the
  clear/draw mechanism itself changes.


---

Canonical page: https://recomposed.blog/draw-discord-profile-status