# CompositionData

Artifact: [androidx.compose.runtime:runtime](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/tooling/CompositionData.kt+class:androidx.compose.runtime.tooling.CompositionData) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0) Common/AllAndroid/JVM
- Cmn

  ```
  interface CompositionData
  ```
Known direct subclasses [CompositionGroup](https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionGroup)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionGroup` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionGroup` is a group of data slots tracked independently by composition. |

*** ** * ** ***

A `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionData` is the data tracked by the composer during composition.

This interface is not intended to be used directly and is provided to allow the tools API to have access to data tracked during composition. The tools API should be used instead which provides a more usable interpretation of the slot table.

## Summary

| ### Public functions |
|---|---|---|
| `open https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionGroup?` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionData#find(kotlin.Any)(identityToFind: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)` Find a sub-group by identity. | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-iterable/index.html<https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionGroup>` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionData#compositionGroups()` Iterate the composition data in the group. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionData#isEmpty()` Returns true if no composition data has been collected. | Cmn |

| ### Extension functions |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionInstance?` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionData.https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionData#(androidx.compose.runtime.tooling.CompositionData).findCompositionInstance()()` Find the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionInstance` associated with the root `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionData`. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/tooling/data/Group` | `@https://developer.android.com/reference/kotlin/androidx/compose/ui/tooling/data/UiToolingDataApi https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionData.https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionData#(androidx.compose.runtime.tooling.CompositionData).asTree()()` Return a group tree for for the slot table that represents the entire content of the slot table. | android |
| `T?` | `@https://developer.android.com/reference/kotlin/androidx/compose/ui/tooling/data/UiToolingDataApi <T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionData.https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionData#(androidx.compose.runtime.tooling.CompositionData).mapTree(kotlin.Function3,androidx.compose.ui.tooling.data.ContextCache)( factory: (https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionGroup, https://developer.android.com/reference/kotlin/androidx/compose/ui/tooling/data/SourceContext, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<T>) -> T?, cache: https://developer.android.com/reference/kotlin/androidx/compose/ui/tooling/data/ContextCache )` Return a tree of custom nodes for the slot table. | android |

## Public functions

### find

Cmn Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.3.0)

```
open fun find(identityToFind: Any): CompositionGroup?
```

Find a sub-group by identity. Returns `null` if the group is not found or the implementation of this interface does not support finding groups by their identity. In other words, a `null` result from this method should not be interpreted as the identity is not a group in the composition data.

## Public properties

### compositionGroups

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
val compositionGroups: Iterable<CompositionGroup>
```

Iterate the composition data in the group. The composition data is structured as a tree of values that corresponds to the call graph of the functions that produced the tree. Interspersed are groups that represents the nodes themselves.

### isEmpty

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.0.0)

```
val isEmpty: Boolean
```

Returns true if no composition data has been collected. This occurs when the first composition into this composition data has not completed yet or, if it is a group, it doesn't contain any child groups.

## Extension functions

### CompositionData.findCompositionInstance

Cmn Artifact: [androidx.compose.runtime:runtime](https://developer.android.com/jetpack/androidx/releases/compose-runtime) [View Source](https://cs.android.com/search?q=file:androidx/compose/runtime/tooling/CompositionData.kt+function:findCompositionInstance)

```
fun CompositionData.findCompositionInstance(): CompositionInstance?
```

Find the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionInstance` associated with the root `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionData`. This is only valid for instances of `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionData` that are recorded in a `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/package-summary#LocalInspectionTables()` table directly.

Even though `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionGroup`s implement the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionData` interface, only the root `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionData` has an associated `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionInstance`. All `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionGroup` instances will return `null`.

### CompositionData.asTree

android Artifact: [androidx.compose.ui:ui-tooling-data](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/tooling/data/SlotTree.jvmAndAndroid.kt+function:asTree)

```
@UiToolingDataApi
fun CompositionData.asTree(): Group
```

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

### CompositionData.mapTree

android Artifact: [androidx.compose.ui:ui-tooling-data](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/tooling/data/SlotTree.jvmAndAndroid.kt+function:mapTree)

```
@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 `https://developer.android.com/reference/kotlin/androidx/compose/ui/tooling/data/package-summary#(androidx.compose.runtime.tooling.CompositionData).mapTree(kotlin.Function3,androidx.compose.ui.tooling.data.ContextCache)` method will be called for every `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionGroup` in the slot tree and can be used to create custom nodes based on the passed arguments. The `https://developer.android.com/reference/kotlin/androidx/compose/ui/tooling/data/SourceContext` argument gives access to additional information encoded in the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionGroup#sourceInfo()`. A return of null from `https://developer.android.com/reference/kotlin/androidx/compose/ui/tooling/data/package-summary#(androidx.compose.runtime.tooling.CompositionData).mapTree(kotlin.Function3,androidx.compose.ui.tooling.data.ContextCache)` means that the entire subtree will be ignored.

A `https://developer.android.com/reference/kotlin/androidx/compose/ui/tooling/data/package-summary#(androidx.compose.runtime.tooling.CompositionData).mapTree(kotlin.Function3,androidx.compose.ui.tooling.data.ContextCache)` can optionally be specified. If a client is calling `https://developer.android.com/reference/kotlin/androidx/compose/ui/tooling/data/package-summary#(androidx.compose.runtime.tooling.CompositionData).mapTree(kotlin.Function3,androidx.compose.ui.tooling.data.ContextCache)` multiple times, this can save some time if the values of `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionGroup#sourceInfo()` are not unique.