# rememberDeferredTransition

Common/All

## Functions summary

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransition<T>` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable <T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/animation/core/rememberDeferredTransition.composable#rememberDeferredTransition(androidx.compose.animation.core.DeferredTransitionState,kotlin.String)( transitionState: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState<T>, label: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html? )` Creates and remembers a `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransition` for a given `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState`. | Cmn |

## Functions

### rememberDeferredTransition

Cmn Artifact: [androidx.compose.animation:animation-core](https://developer.android.com/jetpack/androidx/releases/compose-animation) [View Source](https://cs.android.com/search?q=file:androidx/compose/animation/core/Transition.kt+function:rememberDeferredTransition) Added in [1.13.0-rc01](https://developer.android.com/jetpack/androidx/releases/compose-animation#1.13.0-rc01)

```
@Composable
fun <T : Any?> rememberDeferredTransition(
    transitionState: DeferredTransitionState<T>,
    label: String? = null
): DeferredTransition<T>
```

Creates and remembers a `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransition` for a given `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState`.

A `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransition` allows for a two-stage state update:

1. **Deferred Phase:** Initiated by `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#defer(kotlin.Any)`. The transition's `targetState` remains unchanged, while the new target is exposed via `pendingTargetState`. This allows higher-level components to implement custom behavior (e.g., manual gesture tracking) while the automatic transition is "held".

2. **Automatic Phase:** Initiated by `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#animateTo(kotlin.Any)`. The `pendingTargetState` is cleared and `targetState` is updated, starting the automatic transition animations.

```kotlin
import androidx.compose.animation.core.DeferredTransitionState
import androidx.compose.animation.core.Transition
import androidx.compose.animation.core.animateFloat
import androidx.compose.animation.core.rememberDeferredTransition
import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.graphicsLayer

var targetState by remember { mutableStateOf("Initial") }
var isDeferred by remember { mutableStateOf(false) }

// Create a DeferredTransitionState
val transitionState = remember { DeferredTransitionState(targetState) }

// Use LaunchedEffect to handle defer/animateTo logic based on some external signal
// (e.g. gesture progress, predictive back events, etc).
LaunchedEffect(targetState, isDeferred) {
    if (isDeferred) {
        // Enter deferred phase: targetState is updated as a pendingTargetState
        // but animations don't start yet.
        transitionState.defer(targetState)
    } else {
        // Start automatic transition: pendingTargetState is cleared and targetState is updated
        // to trigger animations.
        transitionState.animateTo(targetState)
    }
}

val transition = rememberDeferredTransition(transitionState)
// Create animations as usual
val alpha by transition.animateFloat { state -> if (state == "Initial") 0f else 1f }

Box(Modifier.graphicsLayer { this.alpha = alpha }) {
    // Content
}
```

| Parameters |
|---|---|
| `transitionState: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState<T>` | The `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState` that manages the current and target states. |
| `label: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html? = null` | An optional label for the transition to be displayed in Android Studio's Animation Preview. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransition<T>` | A `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransition` that will update whenever `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/package-summary#rememberDeferredTransition(androidx.compose.animation.core.DeferredTransitionState,kotlin.String)` changes. |