LavaUI docs

struct DrawState

Swift

@propertyWrapper struct DrawState<Value>

View-local state whose changes only require re-emitting pixels.

Use this for transient values consumed by an already-retained paint closure: a canvas cursor, drag boundary, hover position, or animation phase. Unlike State, reads deliberately do not participate in body observation, and a write raises only .redraw. The storage still survives view reconstruction.

Do not use DrawState for values that change view structure, text outside the paint closure, or layout; those require ordinary State.

Writing one from inside a paint closure requires a change check. The setter raises .redraw on every write, unconditionally — it cannot compare, because Value is not Equatable here. A write from inside paint therefore re-dirties the very frame being painted, and the loop renders again at once rather than sleeping, so an assignment that keeps producing the same value never stops asking for another frame. The tab strip's auto-scroll hit this: scrollX = max(0, scrollX - speed) is a no-op once the row is panned to its end, and it pinned the client at ~1000 paints a second — with the compositor saturated behind it — until the process was killed. Compare first and assign only on a real change; a value that genuinely moves every frame should pace itself with FrameScheduler.requestWake(in:) instead.

Sources/LavaUI/State.swift:87

Constructors

init(wrappedValue: Value)

Not documented.

Sources/LavaUI/State.swift:99

Properties

var wrappedValue: Value { get nonmutating set }

Not documented.

Sources/LavaUI/State.swift:103