Skip to Content
CrowCrow

Custom Drawing & AGSL Shaders

Allocation-free DrawScope with drawBehind, drawWithContent, Canvas, Brush gradients, and reactive Android AGSL ShaderBrush.

When standard containers and styles aren't enough, Crow UI exposes an allocation-free DrawScope and first-class Android AGSL runtime shaders — powered by the exact same reactive graph as everything else.

drawBehind, drawWithContent & Canvas

Attach custom vector drawing anywhere in a modifier chain, or create a dedicated Canvas leaf:

Canvas(Modifier.size(48.dp)) {
    drawArc(
        color = AccentViolet,
        startAngle = -90f,
        sweepAngle = progress.value * 360f,
        useCenter = false,
        style = DrawStyle.Stroke(4.dp.toPx(), cap = StrokeCap.Round),
    )
}
  • Fine-grained draw tracking: Inside drawBehind, drawWithContent, and Canvas, Crow UI wraps execution in reaction(). Reading a signal or Animatable inside the draw block re-records only that single node's display list when the value changes — zero layout pass, zero tree traversal.
  • Chain-order accurate: Modifier.drawBehind { } and Modifier.drawWithContent { drawContent(); ... } execute at their exact position relative to padding, clip, and border.

Brushes & Reactive AGSL Shaders

Crow provides a Brush hierarchy (Brush.solid, Brush.linearGradient, Brush.radialGradient) plus Android's ShaderBrush for custom AGSL (RuntimeShader) programs with a mandatory graceful fallback for devices below API 33:

// Declaring `uniform float uTime;` in AGSL feeds elapsed seconds from Motion.clock automatically.
val auroraBrush = ShaderBrush(
    agsl = AURORA_AGSL_SOURCE,
    fallback = Brush.linearGradient(listOf(0xFF5B3DF5.toInt(), 0xFFB07CFF.toInt())),
    uniforms = {
        float2("uResolution", width, height)
        float2("uTouch", touchX.value, touchY.value)
        color("uAccent", theme.accent)
    },
)

Box(
    Modifier
        .fillMaxWidth()
        .height(220.dp)
        .clip(RoundedCornerShape(24.dp))
        .background(auroraBrush),
)

Why Crow Shaders Feel Effortless

  • Reactive uniforms: Reading signals or Animatable values inside uniforms = { ... } tracks them directly in the draw phase — animating a shader uniform never triggers layout or recomposition.
  • Dormancy-aware uTime: Reading the motion clock automatically pauses when a screen becomes dormant in the back stack or the app moves to the background.
  • Works everywhere: Pass any Brush or ShaderBrush to Modifier.background(brush) or any DrawScope primitive (drawRect, drawRoundRect, drawCircle, drawArc).

How is this guide?

On this page