# CompositionRegistrationObserver

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/CompositionObserver.kt+class:androidx.compose.runtime.tooling.CompositionRegistrationObserver) Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/compose-runtime#1.8.0) Common/AllAndroid/JVM
- Cmn

  ```
  @ExperimentalComposeRuntimeApi
  interface CompositionRegistrationObserver
  ```

*** ** * ** ***

Observe when new compositions are added to a recomposer. This, combined with, `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionObserver`, allows observing when any composition is being performed.

This observer is registered with a `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer` by calling `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/package-summary#(androidx.compose.runtime.Recomposer).observe(androidx.compose.runtime.tooling.CompositionRegistrationObserver)`.

## Summary

| ### Public functions |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionRegistrationObserver#onCompositionRegistered(androidx.compose.runtime.tooling.ObservableComposition)(composition: https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/ObservableComposition)` Called whenever a `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composition` is registered with a `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer` for which this is an observer. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionRegistrationObserver#onCompositionUnregistered(androidx.compose.runtime.tooling.ObservableComposition)(composition: https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/ObservableComposition)` Called whenever a `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composition` is unregistered with a `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer` for which this is an observer. | Cmn |

## Public functions

### onCompositionRegistered

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

```
fun onCompositionRegistered(composition: ObservableComposition): Unit
```

Called whenever a `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composition` is registered with a `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer` for which this is an observer. A Composition is registered with its Recomposer when it begins its initial composition, before any content is added. When a `https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/CompositionRegistrationObserver` is registered, this method will be called for all the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer`'s currently known composition.

This method is called on the same thread that the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composition` being registered is being composed on. During the initial dispatch, it is invoked on the same thread that the callback is being registered on. Implementations of this method should be thread safe as they might be called on an arbitrary thread.

| Parameters |
|---|---|
| `composition: https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/ObservableComposition` | The `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composition` instance that is being registered with the recomposer. |

### onCompositionUnregistered

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

```
fun onCompositionUnregistered(composition: ObservableComposition): Unit
```

Called whenever a `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composition` is unregistered with a `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Recomposer` for which this is an observer. A Composition is unregistered from its Recomposer when the composition is `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composition#dispose()`. This method is called on the same thread that the `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composition` being unregistered was composed on. Implementations of this method should be thread safe as they might be called on an arbitrary thread.

| Parameters |
|---|---|
| `composition: https://developer.android.com/reference/kotlin/androidx/compose/runtime/tooling/ObservableComposition` | The `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composition` instance that is being unregistered with the recomposer. |