ComponentNode

The stateful counterpart of an NodeElement, created once per slot and kept across recompositions.

onAttach runs once, before the owning NodeElement's first update pushes the latest data onto the node's fields. So a listener installed in onAttach is live before the first update lands, and every field it reads needs an initial value that stands until then. onDetach runs when the element leaves the modifier or the node is released or reused, to restore a captured original or remove an installed listener. A reused or deactivated node gets onReset first.

Property nodes come apart in the reverse of the order the modifier declared them last, so a node putting back what it read finds every node declared before it still standing. Subscription nodes are held by position instead, and come apart after the property diff has restored what left the modifier and applied what stands, so what one of them reads as it goes is what the pass leaves behind.

Subclass this to back a custom NodeElement: capture the property's original in a field in onAttach, write the new value in update, and restore it in onDetach. See docs/MODIFIERS.md.

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard

The typed target, valid from onAttach until onDetach. Reading it outside that window - before the node is attached, or after it has been detached - fails.

Link copied to clipboard
val coroutineScope: CoroutineScope

A scope that runs for as long as this node is attached, on the composition's own coroutine context and frame clock. Created on first access and cancelled once onDetach returns.

Link copied to clipboard

Whether this node is attached to a composition.

Link copied to clipboard
open override val shouldAutoInvalidate: Boolean

Component nodes write their own component directly and opt into listener handoff where needed.

Functions

Link copied to clipboard
open fun onAttach()

Runs once every node of the chain is attached. Runs again only after onDetach.

Link copied to clipboard
open fun onDetach()

Runs when the entry leaves the modifier or the node is released, deactivated or reused, while every node of its chain is still attached.

Link copied to clipboard
open fun onReset()

Runs while the node is attached, right before the composition reuses its component for different content or deactivates it. Drop state tied to the old content; onDetach follows.

Link copied to clipboard

Visits the nodes of the modifier this node is attached in that hold a place in it, in the order the modifier declares them: every ComponentNode of an additive element, and every ParentLayoutNode. This node is among them if it is one of those. Visits nothing while this node is not attached.