Google is committed to advancing racial equity for Black communities. See how.

Composer

class Composer<N>
kotlin.Any
   ↳ androidx.compose.runtime.Composer

Implementation of a composer for mutable tree.

Summary

Public constructors
<init>(slotTable: SlotTable, applier: Applier<N>, parentReference: CompositionReference)

Implementation of a composer for mutable tree.

Public methods
Unit

Apply the changes to the tree that were collected during the last composition.

T
cache(invalid: Boolean, block: () -> T)

Cache a value in the composition.

Boolean
changed(value: Any?)

Determine if the current slot table value is equal to the given value, if true, the value is scheduled to be skipped during applyChanges and changes return false; otherwise applyChanges will update the slot table to value.

Boolean
changed(value: Char)

Boolean
changed(value: Byte)

Boolean
changed(value: Short)

Boolean
changed(value: Boolean)

Boolean
changed(value: Float)

Boolean
changed(value: Long)

Boolean
changed(value: Double)

Boolean
changed(value: Int)

Unit

Start collecting key source information.

Unit
composeInitial(block: () -> Unit)

Synchronously compose the initial composition of block.

Unit
createNode(factory: () -> T)

Schedule a node to be created and inserted at the current location.

Unit
emitNode(node: Any?)

Schedule the given node to be inserted.

Unit

Warning: This is expected to be executed by the compiler only and should not be called directly from source code.

Unit

Indicates the end of a "Movable Group" at the current execution position.

Unit

Called to end the node group.

Unit

Indicates the end of a "Replaceable Group" at the current execution position.

ScopeUpdateScope?

End a restart group.

Any
joinKey(left: Any?, right: Any?)

Create a composed key that can be used in calls to startGroup or startNode.

Any?

Return the next value in the slot table and advance the current location.

Boolean

Synchronously recompose all invalidated groups.

Unit

Record that the objects in values have been modified.

Unit
recordReadOf(value: Any)

Record that value was read from.

Unit

Record that value was written to during composition.

Unit

Skip a group.

Unit

Skip to the end of the group opened by startGroup.

Unit

Warning: This is expected to be executed by the compiler only and should not be called directly from source code.

Unit
startMovableGroup(key: Int, dataKey: Any?)

Inserts a "Movable Group" starting marker in the slot table at the current execution position.

Unit
startMovableGroup(key: Int, dataKey: Any?, sourceInformation: String?)

Unit

Start emitting a node.

Unit

Inserts a "Replaceable Group" starting marker in the slot table at the current execution position.

Unit
startReplaceableGroup(key: Int, sourceInformation: String?)

Unit

Start a restart group.

Unit
startRestartGroup(key: Int, sourceInformation: String?)

N

Return the instance of the node that was inserted at the given location.

Extension functions
From androidx.compose.ui
Modifier

Materialize any instance-specific composed modifiers for applying to a raw tree node.

Properties
Applier<N>

An adapter that applies changes to the tree using the Applier abstraction.

CoroutineContext

Int

Returns the hash of the compound key calculated as a combination of the keys of all the currently started groups via startGroup.

Boolean

Boolean

True if the composition is currently scheduling nodes to be inserted into the tree.

Boolean

True if the composition should be checking if the composable functions can be skipped.

SlotTable

Backing storage for the composition

Public constructors

<init>

Composer(
    slotTable: SlotTable,
    applier: Applier<N>,
    parentReference: CompositionReference)

Implementation of a composer for mutable tree.

Public methods

applyChanges

fun applyChanges(): Unit

Apply the changes to the tree that were collected during the last composition.

cache

inline fun <T> cache(
    invalid: Boolean,
    block: () -> T
): T

Cache a value in the composition. During initial composition block is called to produce the value that is then stored in the slot table. During recomposition, if invalid is false the value is obtained from the slot table and block is not invoked. If invalid is false a new value is produced by calling block and the slot table is updated to contain the new value.

changed

fun changed(value: Any?): Boolean

Determine if the current slot table value is equal to the given value, if true, the value is scheduled to be skipped during applyChanges and changes return false; otherwise applyChanges will update the slot table to value. In either case the composer's slot table is advanced.

Parameters
value: Any? the value to be compared.

changed

fun changed(value: Char): Boolean

changed

fun changed(value: Byte): Boolean

changed

fun changed(value: Short): Boolean

changed

fun changed(value: Boolean): Boolean

changed

fun changed(value: Float): Boolean

changed

fun changed(value: Long): Boolean

changed

fun changed(value: Double): Boolean

changed

fun changed(value: Int): Boolean

collectKeySourceInformation

fun collectKeySourceInformation(): Unit

Start collecting key source information. This enables enables the tool API to be able to determine the source location of where groups and nodes are created.

composeInitial

fun composeInitial(block: () -> Unit): Unit

Synchronously compose the initial composition of block. This collects all the changes which must be applied by applyChanges to build the tree implied by block.

createNode

fun <T : N> createNode(factory: () -> T): Unit

Schedule a node to be created and inserted at the current location. This is only valid to call when the composer is inserting.

emitNode

fun emitNode(node: Any?): Unit

Schedule the given node to be inserted. This is only valid to call when the composer is inserting.

endDefaults

fun endDefaults(): Unit

Warning: This is expected to be executed by the compiler only and should not be called directly from source code. Call this API at your own risk.

endMovableGroup

fun endMovableGroup(): Unit

Indicates the end of a "Movable Group" at the current execution position. A Movable Group is a group which can be moved or reordered between its siblings and retain slot table state, in addition to being removed or inserted. These groups are only valid when they are inserted as direct children of Container Groups. Movable Groups are more expensive than other groups because when they are encountered with a mismatched key in the slot table, they must be held on to temporarily until the entire parent group finishes execution in case it moved to a later position in the group. Movable groups are only inserted by the compiler as a result of calls to key.

Warning: This is expected to be executed by the compiler only and should not be called directly from source code. Call this API at your own risk.

endNode

fun endNode(): Unit

Called to end the node group.

endReplaceableGroup

fun endReplaceableGroup(): Unit

Indicates the end of a "Replaceable Group" at the current execution position. A Replaceable Group is a group which cannot be moved between its siblings, but can be removed or inserted. These groups are inserted by the compiler around branches of conditional logic in Composable functions such as if expressions, when expressions, early returns, and null-coalescing operators.

Warning: This is expected to be executed by the compiler only and should not be called directly from source code. Call this API at your own risk.

endRestartGroup

fun endRestartGroup(): ScopeUpdateScope?

End a restart group. If the recompose scope was marked used during composition then a ScopeUpdateScope is returned that allows attaching a lambda that will produce the same composition as was produced by this group (including calling startRestartGroup and endRestartGroup).

joinKey

fun joinKey(
    left: Any?,
    right: Any?
): Any

Create a composed key that can be used in calls to startGroup or startNode. This will use the key stored at the current location in the slot table to avoid allocating a new key.

nextSlot

fun nextSlot(): Any?

Return the next value in the slot table and advance the current location.

recompose

fun recompose(): Boolean

Synchronously recompose all invalidated groups. This collects the changes which must be applied by applyChanges to have an effect.

recordModificationsOf

fun recordModificationsOf(values: Set<Any>): Unit

Record that the objects in values have been modified. This invalidates any recomposes scopes that were current when recordReadOf was called with an instance in values.

This should only be calle when this composition is not actively composing.

recordReadOf

fun recordReadOf(value: Any): Unit

Record that value was read from. If recordWriteOf or recordModificationsOf is called with value then the corresponding currentRecomposeScope is invalidated.

This should only be called when this composition is actively composing.

recordWriteOf

fun recordWriteOf(value: Any): Unit

Record that value was written to during composition. This invalidates all scopes that were current when recordReadOf was called with value yet to be composed. If a scope has already been composed a request is made to the recomposer to recompose the composition.

This should only be called when this composition is actively composing.

skipCurrentGroup

fun skipCurrentGroup(): Unit

Skip a group. Skips the group at the current location. This is only valid to call if the composition is not inserting.

skipToGroupEnd

fun skipToGroupEnd(): Unit

Skip to the end of the group opened by startGroup.

startDefaults

fun startDefaults(): Unit

Warning: This is expected to be executed by the compiler only and should not be called directly from source code. Call this API at your own risk.

startMovableGroup

fun startMovableGroup(
    key: Int,
    dataKey: Any?
): Unit

Inserts a "Movable Group" starting marker in the slot table at the current execution position. A Movable Group is a group which can be moved or reordered between its siblings and retain slot table state, in addition to being removed or inserted. Movable Groups are more expensive than other groups because when they are encountered with a mismatched key in the slot table, they must be held on to temporarily until the entire parent group finishes execution in case it moved to a later position in the group. Movable groups are only inserted by the compiler as a result of calls to key.

A call to startMovableGroup must be matched with a corresponding call to endMovableGroup.

Warning: This is expected to be executed by the compiler only and should not be called directly from source code. Call this API at your own risk.

Parameters
key: Int The source-location-based key for the group. Expected to be unique among its siblings.
dataKey: Any? Additional identifying information to compound with key. If there are multiple values, this is expected to be compounded together with joinKey. Whatever value is passed in here is expected to have a meaningful equals and hashCode implementation.

startMovableGroup

fun startMovableGroup(
    key: Int,
    dataKey: Any?,
    sourceInformation: String?
): Unit

startNode

fun startNode(): Unit

Start emitting a node. It is required that one of emitNode or createNode is called after startNode. Similar to startGroup, if, during recomposition, the current node does not have the provided key a node with that key is scanned for and moved into the current position if found, if no such node is found the composition switches into insert mode and a the node is scheduled to be inserted at the current location.

startReplaceableGroup

fun startReplaceableGroup(key: Int): Unit

Inserts a "Replaceable Group" starting marker in the slot table at the current execution position. A Replaceable Group is a group which cannot be moved between its siblings, but can be removed or inserted. These groups are inserted by the compiler around branches of conditional logic in Composable functions such as if expressions, when expressions, early returns, and null-coalescing operators.

A call to startReplaceableGroup must be matched with a corresponding call to endReplaceableGroup.

Warning: This is expected to be executed by the compiler only and should not be called directly from source code. Call this API at your own risk.

Parameters
key: