Start native apps faster with the Composables CLI ->
Interface

Composer

Composer is the interface that is targeted by the Compose Kotlin compiler plugin and used by code generation helpers.

Source set: Common
public sealed interface Composer

Composer is the interface that is targeted by the Compose Kotlin compiler plugin and used by code generation helpers. It is highly recommended that direct calls these be avoided as the runtime assumes that the calls are generated by the compiler and contain only a minimum amount of state validation.

Properties

applier

Source set: Common
@ComposeCompilerApi public val applier: Applier<*>

A Compose compiler plugin API. DO NOT call directly.

Changes calculated and recorded during composition and are sent to applier which makes the physical changes to the node tree implied by a composition.

Composition has two discrete phases, 1) calculate and record changes and 2) making the changes via the applier. While a Composable functions is executing, none of the applier methods are called. The recorded changes are sent to the applier all at once after all Composable functions have completed.

inserting

Source set: Common
@ComposeCompilerApi public val inserting: Boolean

A Compose compiler plugin API. DO NOT call directly.

Reflects that a new part of the composition is being created, that is, the composition will insert new nodes into the resulting tree.

skipping

Source set: Common
@ComposeCompilerApi public val skipping: Boolean

A Compose compiler plugin API. DO NOT call directly.

Reflects whether the Composable function can skip. Even if a Composable function is called with the same parameters it might still need to run because, for example, a new value was provided for a CompositionLocal created by staticCompositionLocalOf.

defaultsInvalid

Source set: Common
@ComposeCompilerApi public val defaultsInvalid: Boolean

A Compose compiler plugin API. DO NOT call directly.

Reflects whether the default parameter block of a Composable function is valid. This is false if a State object read in the startDefaults group was modified since the last time the Composable function was run.

recomposeScope

Source set: Common
@InternalComposeApi public val recomposeScope: RecomposeScope?

A Compose internal property. DO NOT call directly. Use currentRecomposeScope instead.

The invalidation current invalidation scope. An new invalidation scope is created whenever startRestartGroup is called. when this scope's RecomposeScope.invalidate is called then lambda supplied to endRestartGroup's ScopeUpdateScope will be scheduled to be run.

recomposeScopeIdentity

Source set: Common
@ComposeCompilerApi public val recomposeScopeIdentity: Any?

A Compose compiler plugin API. DO NOT call directly.

Return an object that can be used to uniquely identity of the current recomposition scope. This identity will be the same even if the recompose scope instance changes.

This is used internally by tooling track composable function invocations.

compoundKeyHash

Source set: Common
@Deprecated(
        "Prefer the higher-precision compositeKeyHashCode instead",
        ReplaceWith("compositeKeyHashCode"),
    )
    public val compoundKeyHash: Int

A Compose internal property. DO NOT call directly. Use currentCompositeKeyHash instead.

This a hash value used to map externally stored state to the composition. For example, this is used by saved instance state to preserve state across activity lifetime boundaries.

This value is likely but not guaranteed to be unique. There are known cases, such as for loops without a unique key, where the runtime does not have enough information to make the compound key hash unique.

compositeKeyHashCode

Source set: Common
@InternalComposeApi public val compositeKeyHashCode: CompositeKeyHashCode

A Compose internal property. DO NOT call directly. Use currentCompositeKeyHashCode instead.

This a hash value used to map externally stored state to the composition. For example, this is used by saved instance state to preserve state across activity lifetime boundaries.

This value is likely but not guaranteed to be unique. There are known cases, such as for loops without a unique key, where the runtime does not have enough information to make the compound key hash unique.

currentMarker

Source set: Common
@ComposeCompilerApi public val currentMarker: Int

A Compose compiler plugin API. DO NOT call directly.

Return a marker for the current group that can be used in a call to endToMarker.

currentCompositionLocalMap

Source set: Common
public val currentCompositionLocalMap: CompositionLocalMap

Returns the active set of CompositionLocals at the current position in the composition hierarchy. This is a lower level API that can be used to export and access CompositionLocal values outside of Composition.

This API does not track reads of CompositionLocals and does not automatically dispatch new values to previous readers when the value of a CompositionLocal changes. To use this API as intended, you must set up observation manually. This means:

    to observe the snapshot state for CompositionLocals being read to be notified when their values in this map change.

  • For non-static CompositionLocals, composables reading this map need
  • composable reading this map will be recomposed and you will need to re-obtain this map to get the latest values.

  • For static CompositionLocals, all composables including the

Most applications shouldn't use this API directly, and should instead use CompositionLocal.current.

compositionData

Source set: Common
public val compositionData: CompositionData

A tooling API function. DO NOT call directly.

The data stored for the composition. This is used by Compose tools, such as the preview and the inspector, to display or interpret the result of composition.

applyCoroutineContext

Source set: Common
public val applyCoroutineContext: CoroutineContext

A Compose internal function. DO NOT call directly.

The coroutine context for the composition. This is used, for example, to implement LaunchedEffect. This context is managed by the Recomposer.

composition

Source set: Common
public val composition: ControlledComposition

The composition that is used to control this composer.

Functions

startReplaceableGroup

Source set: Common
@ComposeCompilerApi public fun startReplaceableGroup(key: Int)

A Compose compiler plugin API. DO NOT call directly.

Start a replaceable group. A replaceable group is a group that cannot be moved during execution and can only either inserted, removed, or replaced. For example, the group created by most control flow constructs such as an if statement are replaceable groups.

Warning: Versions of the compiler that generate calls to this function also contain subtle bug that does not generate a group around a loop containing code that just creates composable lambdas (AnimatedContent from androidx.compose.animation, for example) which makes replacing the group unsafe and the this must treat this like a movable group. startReplaceGroup was added that will replace the group as described above and is only called by versions of the compiler that correctly generate code around loops that create lambdas. This method is kept to maintain compatibility with code generated by older versions of the compose compiler plugin.

Parameters

key A compiler generated key based on the source location of the call.

endReplaceableGroup

Source set: Common
@ComposeCompilerApi public fun endReplaceableGroup()

A Compose compiler plugin API. DO NOT call directly.

Called at the end of a replaceable group.

startReplaceGroup

Source set: Common
@ComposeCompilerApi public fun startReplaceGroup(key: Int)

A Compose compiler plugin API. DO NOT call directly.

Start a replace group. A replace group is a group that cannot be moved during must only either be inserted, removed, or replaced. For example, the group created by most control flow constructs such as an if statement are replaceable groups.

Note: This method replaces startReplaceableGroup which is only generated by older versions of the compose compiler plugin that predate the addition of this method. The runtime is now required to replace the group if a different group is detected instead of treating it like a movable group.

Parameters

key A compiler generated key based on the source location of the call.

endReplaceGroup

Source set: Common
@ComposeCompilerApi public fun endReplaceGroup()

A Compose compiler plugin API. DO NOT call directly.

Called at the end of a replace group.

startMovableGroup

Source set: Common
@ComposeCompilerApi public fun startMovableGroup(key: Int, dataKey: Any?)

A Compose compiler plugin API. DO NOT call directly.

Start a movable group. A movable group is one that can be moved based on the value of dataKey which is typically supplied by the key pseudo compiler function.

A movable group implements the semantics of key which allows the state and nodes generated by a loop to move with the composition implied by the key passed to key.

Parameters

key a compiler generated key based on the source location of the call.
dataKey an additional object that is used as a second part of the key. This key produced from the keys parameter supplied to the key pseudo compiler function.

endMovableGroup

Source set: Common
@ComposeCompilerApi public fun endMovableGroup()

A Compose compiler plugin API. DO NOT call directly.

Called at the end of a movable group.

startDefaults

Source set: Common
@ComposeCompilerApi public fun startDefaults()

A Compose compiler plugin API. DO NOT call directly.

Called to start the group that calculates the default parameters of a Composable function.

This method is called near the beginning of a Composable function with default parameters and surrounds the remembered values or Composable calls necessary to produce the default parameters. For example, for model: Model = remember { DefaultModel() } the call to remember is called inside a startDefaults group.

endDefaults

Source set: Common
@ComposeCompilerApi public fun endDefaults()

A Compose compiler plugin API. DO NOT call directly.

Called at the end of defaults group.

startRestartGroup

Source set: Common
@ComposeCompilerApi public fun startRestartGroup(key: Int): Composer

A Compose compiler plugin API. DO NOT call directly.

Called to record a group for a Composable function and starts a group that can be recomposed on demand based on the lambda passed to updateScope when endRestartGroup is called

Parameters

key A compiler generated key based on the source location of the call.

Return

the instance of the composer to use for the rest of the function.

endRestartGroup

Source set: Common
@ComposeCompilerApi public fun endRestartGroup(): ScopeUpdateScope?

A Compose compiler plugin API. DO NOT call directly.

Called to end a restart group.

insertMovableContentReferences

Source set: Common
public fun insertMovableContentReferences(
        references: List<Pair<MovableContentStateReference, MovableContentStateReference?>>
    )

A Compose internal API. DO NOT call directly.

Perform a late composition that adds to the current late apply that will insert the given references to MovableContent into the composition. If a MovableContent is paired then this is a request to move a released MovableContent from a different location or from a different composition. If it is not paired (i.e. the second MovableContentStateReference is null) then new state for the MovableContent is inserted into the composition.

sourceInformation

Source set: Common
public fun sourceInformation(sourceInformation: String)

A Compose compiler plugin API. DO NOT call directly.

Record the source information string for a group. This must be immediately called after the start of a group.

Parameters

sourceInformation An string value to that provides the compose tools enough information to calculate the source location of calls to composable functions.

sourceInformationMarkerStart

Source set: Common
public fun sourceInformationMarkerStart(key: Int, sourceInformation: String)

A compose compiler plugin API. DO NOT call directly.

Record a source information marker. This marker can be used in place of a group that would have contained the information but was elided as the compiler plugin determined the group was not necessary such as when a function is marked with ReadOnlyComposable.

Parameters

key A compiler generated key based on the source location of the call.
sourceInformation An string value to that provides the compose tools enough information to calculate the source location of calls to composable functions.

sourceInformationMarkerEnd

Source set: Common
public fun sourceInformationMarkerEnd()

A compose compiler plugin API. DO NOT call directly.

Record the end of the marked source information range.

skipToGroupEnd

Source set: Common
@ComposeCompilerApi public fun skipToGroupEnd()

A Compose compiler plugin API. DO NOT call directly.

Skips the composer to the end of the current group. This generated by the compiler to when the body of a Composable function can be skipped typically because the parameters to the function are equal to the values passed to it in the previous composition.

deactivateToEndGroup

Source set: Common
@ComposeCompilerApi public fun deactivateToEndGroup(changed: Boolean)

A Compose compiler plugin API. DO NOT call directly.

Deactivates the content to the end of the group by treating content as if it was deleted and replaces all slot table entries for calls to cache to be Empty. This must be called as the first call for a group.

skipCurrentGroup

Source set: Common
@ComposeCompilerApi public fun skipCurrentGroup()

A Compose compiler plugin API. DO NOT call directly.

Skips the current group. This called by the compiler to indicate that the current group can be skipped, for example, this is generated to skip the startDefaults group the default group is was not invalidated.

startNode

Source set: Common
@ComposeCompilerApi public fun startNode()

A Compose compiler plugin API. DO NOT call directly.

Start a group that tracks a the code that will create or update a node that is generated as part of the tree implied by the composition.

startReusableNode

Source set: Common
@ComposeCompilerApi public fun startReusableNode()

A Compose compiler plugin API. DO NOT call directly.

Start a group that tracks a the code that will create or update a node that is generated as part of the tree implied by the composition. A reusable node can be reused in a reusable group even if the group key is changed.

createNode

Source set: Common
@ComposeCompilerApi public fun <T> createNode(factory: () -> T)

A Compose compiler plugin API. DO NOT call directly.

Report the factory that will be used to create the node that will be generated into the tree implied by the composition. This will only be called if inserting is is true.

Parameters

factory a factory function that will generate a node that will eventually be supplied to applier though Applier.insertBottomUp and Applier.insertTopDown.

useNode

Source set: Common
@ComposeCompilerApi public fun useNode()

A Compose compiler plugin API. DO NOT call directly.

Report that the node is still being used. This will be called in the same location as the corresponding createNode when inserting is false.

endNode

Source set: Common
@ComposeCompilerApi public fun endNode()

A Compose compiler plugin API. DO NOT call directly.

Called at the end of a node group.

startReusableGroup

Source set: Common
@ComposeCompilerApi public fun startReusableGroup(key: Int, dataKey: Any?)

A Compose compiler plugin API. DO NOT call directly.

Start a reuse group. Unlike a movable group, in a reuse group if the dataKey changes the composition shifts into a reusing state cause the composer to act like it is inserting (e.g. cache acts as if all values are invalid, changed always returns true, etc.) even though it is recomposing until it encounters a reusable node. If the node is reusable it temporarily shifts into recomposition for the node and then shifts back to reusing for the children. If a non-reusable node is generated the composer shifts to inserting for the node and all of its children.

Parameters

key An compiler generated key based on the source location of the call.
dataKey A key provided by the ReusableContent composable function that is used to determine if the composition shifts into a reusing state for this group.

endReusableGroup

Source set: Common
@ComposeCompilerApi public fun endReusableGroup()

A Compose compiler plugin API. DO NOT call directly.

Called at the end of a reusable group.

disableReusing

Source set: Common
@ComposeCompilerApi public fun disableReusing()

A Compose compiler plugin API. DO NOT call directly.

Temporarily disable reusing if it is enabled.

enableReusing

Source set: Common
@ComposeCompilerApi public fun enableReusing()

A Compose compiler plugin API. DO NOT call directly.

Reenable reusing if it was previously enabled before the last call to disableReusing.

endToMarker

Source set: Common
@ComposeCompilerApi public fun endToMarker(marker: Int)

Compose compiler plugin API. DO NOT call directly.

Ends all the groups up to but not including the group that is the parent group when currentMarker was called to produce marker. All groups ended must have been started with either startReplaceableGroup or startMovableGroup. Ending other groups can cause the state of the composer to become inconsistent.

apply

Source set: Common
@ComposeCompilerApi public fun <V, T> apply(value: V, block: T.(V) -> Unit)

A Compose compiler plugin API. DO NOT call directly.

Schedule block to called with value. This is intended to update the node generated by createNode to changes discovered by composition.

Parameters

value the new value to be set into some property of the node.
block the block that sets the some property of the node to value.

joinKey

Source set: Common
@ComposeCompilerApi public fun joinKey(left: Any?, right: Any?): Any

A Compose compiler plugin API. DO NOT call directly.

Produce an object that will compare equal an iff left and right compare equal to some left and right of a previous call to joinKey. This is used by key to handle multiple parameters. Since the previous composition stored left and right in a "join key" object this call is used to return the previous value without an allocation instead of blindly creating a new value that will be immediately discarded.

Parameters

left the first part of a a joined key.
right the second part of a joined key.

Return

an object that will compare equal to a value previously returned by joinKey iff left and right compare equal to the left and right passed to the previous call.

rememberedValue

Source set: Common
@ComposeCompilerApi public fun rememberedValue(): Any?

A Compose compiler plugin API. DO NOT call directly.

Remember a value into the composition state. This is a primitive method used to implement remember.

Return

Composer.Empty when inserting is true or the value passed to updateRememberedValue from the previous composition.

updateRememberedValue

Source set: Common
@ComposeCompilerApi public fun updateRememberedValue(value: Any?)

A Compose compiler plugin API. DO NOT call directly.

Update the remembered value correspond to the previous call to rememberedValue. The value will be returned by rememberedValue for the next composition.

changed

Source set: Common
@ComposeCompilerApi public fun changed(value: Any?): Boolean

A Compose compiler plugin API. DO NOT call directly.

Check value is different than the value used in the previous composition. This is used, for example, to check parameter values to determine if they have changed.

Parameters

value the value to check

Return

true if the value if equals of the previous value returns false when passed value.

changed

Source set: Common
@ComposeCompilerApi public fun changed(value: Boolean): Boolean

A Compose compiler plugin API. DO NOT call directly.

Check value is different than the value used in the previous composition. This is used, for example, to check parameter values to determine if they have changed.

This overload is provided to avoid boxing value to compare with a potentially boxed version of value in the composition state.

Parameters

value the value to check

Return

true if the value if equals of the previous value returns false when passed value.

changed

Source set: Common
@ComposeCompilerApi public fun changed(value: Char): Boolean

A Compose compiler plugin API. DO NOT call directly.

Check value is different than the value used in the previous composition. This is used, for example, to check parameter values to determine if they have changed.

This overload is provided to avoid boxing value to compare with a potentially boxed version of value in the composition state.

Parameters

value the value to check

Return

true if the value if equals of the previous value returns false when passed value.

changed

Source set: Common
@ComposeCompilerApi public fun changed(value: Byte): Boolean

A Compose compiler plugin API. DO NOT call directly.

Check value is different than the value used in the previous composition. This is used, for example, to check parameter values to determine if they have changed.

This overload is provided to avoid boxing value to compare with a potentially boxed version of value in the composition state.

Parameters

value the value to check

Return

true if the value if equals of the previous value returns false when passed value.

changed

Source set: Common
@ComposeCompilerApi public fun changed(value: Short): Boolean

A Compose compiler plugin API. DO NOT call directly.

Check value is different than the value used in the previous composition. This is used, for example, to check parameter values to determine if they have changed.

This overload is provided to avoid boxing value to compare with a potentially boxed version of value in the composition state.

Parameters

value the value to check

Return

true if the value if equals of the previous value returns false when passed value.

changed

Source set: Common
@ComposeCompilerApi public fun changed(value: Int): Boolean

A Compose compiler plugin API. DO NOT call directly.

Check value is different than the value used in the previous composition. This is used, for example, to check parameter values to determine if they have changed.

This overload is provided to avoid boxing value to compare with a potentially boxed version of value in the composition state.

Parameters

value the value to check

Return

true if the value if equals of the previous value returns false when passed value.

changed

Source set: Common
@ComposeCompilerApi public fun changed(value: Float): Boolean

A Compose compiler plugin API. DO NOT call directly.

Check value is different than the value used in the previous composition. This is used, for example, to check parameter values to determine if they have changed.

This overload is provided to avoid boxing value to compare with a potentially boxed version of value in the composition state.

Parameters

value the value to check

Return

true if the value if equals of the previous value returns false when passed value.

changed

Source set: Common
@ComposeCompilerApi public fun changed(value: Long): Boolean

A Compose compiler plugin API. DO NOT call directly.

Check value is different than the value used in the previous composition. This is used, for example, to check parameter values to determine if they have changed.

This overload is provided to avoid boxing value to compare with a potentially boxed version of value in the composition state.

Parameters

value the value to check

Return

true if the value if equals of the previous value returns false when passed value.

changed

Source set: Common
@ComposeCompilerApi public fun changed(value: Double): Boolean

A Compose compiler plugin API. DO NOT call directly.

Check value is different than the value used in the previous composition. This is used, for example, to check parameter values to determine if they have changed.

This overload is provided to avoid boxing value to compare with a potentially boxed version of value in the composition state.

Parameters

value the value to check

Return

true if the value if equals of the previous value returns false when passed value.

changedInstance

Source set: Common
@ComposeCompilerApi public fun changedInstance(value: Any?): Boolean

A Compose compiler plugin API. DO NOT call directly.

Check value is different than the value used in the previous composition using === instead of == equality. This is used, for example, to check parameter values to determine if they have changed for values that use value equality but, for correct behavior, the composer needs reference equality.

Parameters

value the value to check

Return

true if the value is === equal to the previous value and returns false when value is different.

collectParameterInformation

Source set: Common
public fun collectParameterInformation()

A tooling API function. DO NOT call directly.

Called by the inspector to inform the composer that it should collect additional information about call parameters. By default, only collect parameter information for scopes that are recordUsed has been called on. If collectParameterInformation is called it will attempt to collect all calls even if the runtime doesn't need them.

WARNING: calling this will result in a significant number of additional allocations that are typically avoided.

scheduleFrameEndCallback

Source set: Common
public fun scheduleFrameEndCallback(action: () -> Unit): CancellationHandle

Schedules an action to be invoked when the recomposer finishes the next composition of a frame (including the completion of subcompositions). If a frame is currently in-progress, action will be invoked when the current frame fully finishes composing. If a frame isn't currently in-progress, a new frame will be scheduled (if one hasn't been already) and action will execute at the completion of the next frame's composition. If a new frame is scheduled and there is no other work to execute, action will still execute.

action will always execute on the applier thread.

Note that action runs at the end of a frame scheduled by the recomposer. If a callback is scheduled via this method during the initial composition, it will not execute until the next frame.

Return

A CancellationHandle that can be used to unregister the action. The returned handle is thread-safe and may be cancelled from any thread. Cancelling the handle only removes the callback from the queue. If action is currently executing, it will not be cancelled by this handle.

disableSourceInformation

Source set: Common
@TestOnly public fun disableSourceInformation()

Disable the collection of source information, that may introduce groups to store the source information, in order to be able to more accurately calculate the actual number of groups a composable function generates in a release build.

This function is only safe to call in a test and will produce incorrect composition results if called on a composer not under test.

Members

Companion

Source set: Common
public companion object

Properties

Empty

Source set: Common
public val Empty: Any =
            object {
                override fun toString() = "Empty"
            }

A special value used to represent no value was stored (e.g. an empty slot). This is returned, for example by Composer.rememberedValue while it is Composer.inserting is true.

Functions

setTracer

Source set: Common
public fun setTracer(tracer: CompositionTracer?)

Internal API for specifying a tracer used for instrumenting frequent operations, e.g. recompositions.

setDiagnosticStackTraceMode

Source set: Common
public fun setDiagnosticStackTraceMode(mode: ComposeStackTraceMode)

Set the mode for collecting composition stack traces. See ComposeStackTraceMode for more information about available modes. The stack traces are disabled by default.

Note: changing stack trace collection mode will not affect already running compositions.

setDiagnosticStackTraceEnabled

Source set: Common
@Deprecated(message = "Use setDiagnosticStackTraceMode instead")
        public fun setDiagnosticStackTraceEnabled(enabled: Boolean)

Enable composition stack traces based on the source information. When this flag is enabled, composition will record source information at runtime. When crash occurs, Compose will append a suppressed exception that contains a stack trace pointing to the place in composition closest to the crash.