androidx.compose.ui.tooling.data

Interfaces

SourceContext

Context with data for creating group nodes.

Classes

CallGroup

A group that represents the invocation of a component

ContextCache

A cache of SourceInformationContext that optionally can be specified when using mapTree.

Group

A group in the slot table.

JoinedKey

A key that has being joined together to form one key.

NodeGroup

A group that represents an emitted node

ParameterInformation
SourceLocation

Source location of the call that produced the call group.

Annotations

Extension functions summary

Group

Return a group tree for for the slot table that represents the entire content of the slot table.

List<ParameterInformation>

Return the parameters found for this CompositionGroup.

List<T>
@UiToolingDataApi
<T : Any?> Set<CompositionData>.makeTree(
    factory: (CompositionGroup, SourceContext, List<T>, List<T>) -> T?,
    cache: ContextCache
)

Processes a set of CompositionData instances and constructs a list of trees of custom nodes.

List<R>
@UiToolingDataApi
<T : Any?, R : Any?> Set<CompositionData>.makeTree(
    prepareResult: (CompositionInstance) -> Unit,
    createNode: (CompositionGroup, SourceContext, List<T>, List<R>) -> T?,
    createResult: (CompositionInstance, T?, List<CompositionInstance>) -> R?,
    cache: ContextCache
)

Processes a set of CompositionData instances and constructs a list of trees of custom nodes.

T?
@UiToolingDataApi
<T : Any?> CompositionData.mapTree(
    factory: (CompositionGroup, SourceContext, List<T>) -> T?,
    cache: ContextCache
)

Return a tree of custom nodes for the slot table.

Extension properties summary

String?

The source position of the group extracted from the key, if one exists for the group.

Extension functions

@UiToolingDataApi
fun CompositionData.asTree(): Group

Return a group tree for for the slot table that represents the entire content of the slot table.

findParameters

@UiToolingDataApi
fun CompositionGroup.findParameters(cache: ContextCache? = null): List<ParameterInformation>

Return the parameters found for this CompositionGroup.

@UiToolingDataApi
fun <T : Any?> Set<CompositionData>.makeTree(
    factory: (CompositionGroup, SourceContext, List<T>, List<T>) -> T?,
    cache: ContextCache = ContextCache()
): List<T>

Processes a set of CompositionData instances and constructs a list of trees of custom nodes.

This function builds a hierarchy from the provided compositions and then uses the mapTree to transform each root composition into a custom tree structure defined by the factory. Results from mapTree that are null will be excluded from the final list.

The processing involves:

  1. Building a lookup map from CompositionInstance to CompositionData.

  2. Constructing a parent-to-children hierarchy of CompositionInstances.

  3. Recursively traversing the hierarchy to map each composition using the provided factory, potentially stitching children processed from sub-compositions.

Parameters
Set<CompositionData>

A set of CompositionData to be processed into trees.

factory: (CompositionGroup, SourceContext, List<T>, List<T>) -> T?

A function that takes a CompositionGroup, its SourceContext, a list of already processed children of type T from the current composition, and an optional list of children of type T from stitched sub-compositions. It returns a custom node of type T or null.

cache: ContextCache = ContextCache()

An optional ContextCache to optimize SourceContext creation.

Returns
List<T>

A list of root nodes of type T representing the successfully processed trees.

@UiToolingDataApi
fun <T : Any?, R : Any?> Set<CompositionData>.makeTree(
    prepareResult: (CompositionInstance) -> Unit,
    createNode: (CompositionGroup, SourceContext, List<T>, List<R>) -> T?,
    createResult: (CompositionInstance, T?, List<CompositionInstance>) -> R?,
    cache: ContextCache = ContextCache()
): List<R>

Processes a set of CompositionData instances and constructs a list of trees of custom nodes.

This function builds a hierarchy from the provided compositions and then uses the mapTree to transform each root composition into a custom tree structure defined by the createNode. Results from mapTree that are null will be excluded from the final list.

The processing involves:

  1. Building a lookup map from CompositionInstance to CompositionData.

  2. Constructing a parent-to-children hierarchy of CompositionInstances.

  3. Recursively traversing the hierarchy to map each composition using the provided createNode, potentially stitching children processed from sub-compositions.

Parameters
Set<CompositionData>

A set of CompositionData to be processed into trees.

prepareResult: (CompositionInstance) -> Unit

Give the caller a chance to setup data structures for a composition.

createNode: (CompositionGroup, SourceContext, List<T>, List<R>) -> T?

A function that takes a CompositionGroup, its SourceContext, a list of already processed children of type T from the current composition, and an optional list of children of type R from stitched sub-compositions. It returns a custom node of type R or null.

createResult: (CompositionInstance, T?, List<CompositionInstance>) -> R?

Create a result R from the top node T for this composition and the specified child compositions.

cache: ContextCache = ContextCache()

An optional ContextCache to optimize SourceContext creation.

Returns
List<R>

A list of root nodes of type R representing the successfully processed trees.

@UiToolingDataApi
fun <T : Any?> CompositionData.mapTree(
    factory: (CompositionGroup, SourceContext, List<T>) -> T?,
    cache: ContextCache = ContextCache()
): T?

Return a tree of custom nodes for the slot table.

The factory method will be called for every CompositionGroup in the slot tree and can be used to create custom nodes based on the passed arguments. The SourceContext argument gives access to additional information encoded in the CompositionGroup.sourceInfo. A return of null from factory means that the entire subtree will be ignored.

A cache can optionally be specified. If a client is calling mapTree multiple times, this can save some time if the values of CompositionGroup.sourceInfo are not unique.

Extension properties

@UiToolingDataApi
val Group.positionString?

The source position of the group extracted from the key, if one exists for the group.