# androidx.appstate.transform

Common/All

## Interfaces

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/appstate/transform/DisposableState` | A `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` that can be disposed to stop its underlying state transformation. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/appstate/transform/TransformScope` | A scope that manages a shared headless `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composition` for running one or more state transformations created via `https://developer.android.com/reference/kotlin/androidx/appstate/transform/TransformScope#launchTransform(kotlin.Any,kotlin.Function1)`. | Cmn |

## Composables

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/appstate/transform/transform.composable` | A Composable `https://developer.android.com/reference/kotlin/androidx/appstate/transform/transform.composable#transform(kotlin.Any,kotlinx.coroutines.CoroutineDispatcher,kotlin.Function1)` that remembers the resulting `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` and ties the headless composition to the current `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html` provided by the Compose lifecycle. | Cmn |

## Top-level functions summary

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/appstate/transform/TransformScope` | `https://developer.android.com/reference/kotlin/androidx/appstate/transform/package-summary#TransformScope()()` Creates a `https://developer.android.com/reference/kotlin/androidx/appstate/transform/package-summary#TransformScope()`. | Cmn |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/appstate/transform/package-summary#listener(kotlinx.coroutines.CoroutineDispatcher,kotlin.Function0)(dispatcher: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html, onUpdate: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Suspend function that executes a Composable `https://developer.android.com/reference/kotlin/androidx/appstate/transform/package-summary#listener(kotlinx.coroutines.CoroutineDispatcher,kotlin.Function0)` block in a headless Composition. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State<R>` | `<R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/appstate/transform/package-summary#transform(kotlin.Any,kotlinx.coroutines.CoroutineScope,kotlinx.coroutines.CoroutineDispatcher,kotlin.Function1)( initialValue: R, scope: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html, dispatcher: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html, onUpdate: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable (R) -> R )` This is a convenience function for `https://developer.android.com/reference/kotlin/androidx/appstate/transform/TransformScope#launchTransform(kotlin.Any,kotlin.Function1)` that runs the transform within the given `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html`. | Cmn |

## Top-level functions

### TransformScope

Cmn Artifact: [androidx.appstate.transform:transform](https://developer.android.com/jetpack/androidx/releases/appstate-transform) [View Source](https://cs.android.com/search?q=file:androidx/appstate/transform/TransformScope.kt+function:TransformScope) Added in [1.0.0-alpha02](https://developer.android.com/jetpack/androidx/releases/appstate-transform#1.0.0-alpha02)

```
fun TransformScope(): TransformScope
```

Creates a `https://developer.android.com/reference/kotlin/androidx/appstate/transform/package-summary#TransformScope()`.

### listener

Cmn Artifact: [androidx.appstate.transform:transform](https://developer.android.com/jetpack/androidx/releases/appstate-transform) [View Source](https://cs.android.com/search?q=file:androidx/appstate/transform/Listener.kt+function:listener) Added in [1.0.0-alpha02](https://developer.android.com/jetpack/androidx/releases/appstate-transform#1.0.0-alpha02)

```
suspend fun listener(
    dispatcher: CoroutineDispatcher = Dispatchers.Default,
    onUpdate: @Composable () -> Unit
): Unit
```

Suspend function that executes a Composable `https://developer.android.com/reference/kotlin/androidx/appstate/transform/package-summary#listener(kotlinx.coroutines.CoroutineDispatcher,kotlin.Function0)` block in a headless Composition.

This function bridges reactive Compose state (or Flows collected as state) into a continuously updated `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-state/index.html` object outside of a traditional Compose UI hierarchy. The `https://developer.android.com/reference/kotlin/androidx/appstate/transform/package-summary#listener(kotlinx.coroutines.CoroutineDispatcher,kotlin.Function0)` block is automatically recomposed whenever any Compose state it reads is updated.

| Parameters |
|---|---|
| `dispatcher: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html = Dispatchers.Default` | The `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html` thread this listener should run on. |
| `onUpdate: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | The `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable` block that will be recomposed when its state dependencies change. |

### transform

Cmn Artifact: [androidx.appstate.transform:transform](https://developer.android.com/jetpack/androidx/releases/appstate-transform) [View Source](https://cs.android.com/search?q=file:androidx/appstate/transform/Transform.kt+function:transform) Added in [1.0.0-alpha02](https://developer.android.com/jetpack/androidx/releases/appstate-transform#1.0.0-alpha02)

```
fun <R : Any?> transform(
    initialValue: R,
    scope: CoroutineScope,
    dispatcher: CoroutineDispatcher = Dispatchers.Default,
    onUpdate: @Composable (R) -> R
): State<R>
```

This is a convenience function for `https://developer.android.com/reference/kotlin/androidx/appstate/transform/TransformScope#launchTransform(kotlin.Any,kotlin.Function1)` that runs the transform within the given `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html`.

This function bridges reactive Compose state (or Flows collected as state) into a continuously updated `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` object outside a traditional Compose UI hierarchy. The `https://developer.android.com/reference/kotlin/androidx/appstate/transform/package-summary#transform(kotlin.Any,kotlinx.coroutines.CoroutineScope,kotlinx.coroutines.CoroutineDispatcher,kotlin.Function1)` block is automatically recomposed whenever any Compose state it reads is updated, and the newly returned value is pushed into the resulting `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State`.

| Parameters |
|---|---|
| `initialValue: R` | The initial value to populate the returned `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` before the first composition completes. |
| `scope: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html` | The `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html` in which the recomposer and frame clock will run. |
| `dispatcher: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html = Dispatchers.Default` | The `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html` thread this transform should run on. |
| `onUpdate: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable (R) -> R` | The `https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable` block that computes the value of type `https://developer.android.com/reference/kotlin/androidx/appstate/transform/package-summary#transform(kotlin.Any,kotlinx.coroutines.CoroutineScope,kotlinx.coroutines.CoroutineDispatcher,kotlin.Function1)`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State<R>` | A `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State` containing the latest result of the `https://developer.android.com/reference/kotlin/androidx/appstate/transform/package-summary#transform(kotlin.Any,kotlinx.coroutines.CoroutineScope,kotlinx.coroutines.CoroutineDispatcher,kotlin.Function1)` block. |