Skip to Content
CrowCrow

Components, Props & Control Flow

How @Ui functions, dual-slot live props, @Once parameters, reactive @Props modifiers, if/when regions, and keyed For work.

In Crow, every UI building block is a plain Kotlin function annotated with @Ui. Because components run once at mount, reactivity flows through live props, reactive modifiers, and compiler-lowered control flow.

@Ui Functions & Live Props

Every parameter of a @Ui function is live by default:

@Ui
fun StatusBadge(label: String, active: Boolean, @Once onTap: () -> Unit) {
    Box(
        Modifier
            .clip(RoundedCornerShape(999.dp))
            .background(if (active) AccentViolet else MutedSurface)
            .clickable(onTap)
            .padding(horizontal = 12.dp, vertical = 6.dp),
    ) {
        Text(label)
    }
}

When a caller passes StatusBadge(label = user.name, active = isOnline, onTap = ::openProfile):

  • label and active compile to dual-slot props (a raw value when the caller passes a constant, or a typed getter slot when the caller passes a reactive expression).
  • Reading label or active inside Text(...) or Modifier.background(...) binds straight to the underlying render node.
  • @Once marks a parameter as static-only (onTap, controllers, stores, route keys) — the compiler skips prop-getter generation completely and lets you read it freely inside the component body without triggering CR1001.

@Ui Lambda Props

Parameters of a @Ui lambda (itemContent: @Ui (Item) -> Unit) are also live props. Lists (For, LazyColumn) and NavHost use this so when an item's data changes without changing its key, the lambda does not remount — the existing nodes update in place.

Reactive @Props Modifiers

Modifier factories annotated with @Props (like Modifier.background(color), Modifier.height { ... }, Modifier.graphicsLayer { ... }) accept live reactive expressions without taking a UI scope:

Box(
    Modifier
        .fillMaxWidth()
        .height { if (expanded) 180.dp else 64.dp }
        .background(if (selected) ActiveTint else SurfaceTint, RoundedCornerShape(16.dp)),
)
  • Color changes update the draw phase only (no layout pass).
  • graphicsLayer { alpha = ...; scale = ... } updates the layer phase only (no tree walk, no draw recording).
  • height { ... } / width { ... } re-measures only in the layout phase with zero remounting.

Reactive Control Flow (if / when)

You write ordinary Kotlin if and when statements inside @Ui functions:

@Ui
fun ProfileHeader(isPro: Boolean, tier: Tier) {
    if (isPro) {
        ProBadge()
    }

    when (tier) {
        Tier.Free -> UpgradeBanner()
        Tier.Team -> TeamSeatsBar()
        Tier.Enterprise -> AuditLink()
    }
}

At compile time, crow-compiler inspects the condition:

  1. Dynamic condition (reads a signal or live prop): lowers to uiSwitch, mounting the active branch inside an isolated region with its own Owner. Switching branches disposes the outgoing owner and mounts the incoming branch in place without touching sibling nodes.
  2. Static condition (@Once parameter or plain val): compiles to an ordinary Kotlin branch with zero region or owner overhead.

Keyed Lists (For)

For non-virtualized dynamic collections (chips, form rows, tags, small sections), use For with a stable key:

For(tags, key = { it.id }) { tag ->
    TagChip(
        label = tag.name,
        selected = tag.selected,
        onClick = { toggleTag(tag.id) },
    )
}
  • Each key gets its own ordered region and Owner.
  • Reordering moves only items outside the longest increasing subsequence — local state inside each row survives moves intact.
  • Updating an item's fields delivers the new value as a live prop to the existing entry without remounting it.
  • For large scrollable feeds, use LazyColumn / LazyVerticalGrid.

How is this guide?

On this page