# DeferredTransitionState

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+class:androidx.compose.animation.core.DeferredTransitionState) Added in [1.12.0](https://developer.android.com/jetpack/androidx/releases/compose-animation#1.12.0) Common/All
- Cmn

  ```
  class DeferredTransitionState<S : Any?> : TransitionState<S>
  ```

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [androidx.compose.animation.core.TransitionState](https://developer.android.com/reference/kotlin/androidx/compose/animation/core/TransitionState)\<S\> ||
|   | ↳ | [androidx.compose.animation.core.DeferredTransitionState](https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState) |

*** ** * ** ***

A `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/TransitionState` that supports a deferred phase before the automatic transition begins.

This state is designed for scenarios where a transition should be held in an intermediate, manually-controlled state (e.g., during a predictive back gesture) before proceeding to its final target.

While in the deferred phase (initiated by `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#defer(kotlin.Any)`), the transition holds the new target as a `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#pendingTargetState()`. The actual `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#targetState()` remains unchanged, keeping the transition in its current visual state. Once `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#animateTo(kotlin.Any)` is called, the `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#pendingTargetState()` is cleared and the transition proceeds to the new `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#targetState()`, triggering its automatic 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
}
```

## Summary

| ### Public constructors |
|---|---|
| `<S : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#DeferredTransitionState(kotlin.Any)(initialState: S)` | Cmn |

| ### Public functions |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#animateTo(kotlin.Any)(targetState: S)` Clears the `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#pendingTargetState()` and updates the `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#animateTo(kotlin.Any)` to the provided `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#animateTo(kotlin.Any)`, ending the deferred phase and starting the automatic transition animation. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#defer(kotlin.Any)(targetState: S)` Updates the `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#pendingTargetState()` and initiates the deferred phase. | Cmn |

| ### Public properties |
|---|---|---|
| `open S` | `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#currentState()` Current state of the transition. | Cmn |
| `S?` | `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#pendingTargetState()` The target state that the transition will eventually animate to once the deferred phase ends. | Cmn |
| `open S` | `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#targetState()` Target state of the transition. | Cmn |

## Public constructors

### DeferredTransitionState

Cmn

```
<S : Any?> DeferredTransitionState(initialState: S)
```

| Parameters |
|---|---|
| `initialState: S` | The initial state of the transition. |

## Public functions

### animateTo

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

```
fun animateTo(targetState: S): Unit
```

Clears the `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#pendingTargetState()` and updates the `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#animateTo(kotlin.Any)` to the provided `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#animateTo(kotlin.Any)`, ending the deferred phase and starting the automatic transition animation.

Note: The `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#animateTo(kotlin.Any)` provided here does not need to match the previous `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#pendingTargetState()`. If a different state is provided, the transition will animate directly to this new state, bypassing the previously deferred target.

| Parameters |
|---|---|
| `targetState: S` | The final target state for the transition. |

### defer

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

```
fun defer(targetState: S): Unit
```

Updates the `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#pendingTargetState()` and initiates the deferred phase.

During this phase, the transition's `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#defer(kotlin.Any)` remains unchanged, keeping the transition in its current visual state. However, the new target is exposed via `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#pendingTargetState()`, signaling to transition-aware components that a state change is pending. They can then use this information to perform early setup or apply custom logic for the pending state before the automatic transition is eventually started via `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#animateTo(kotlin.Any)`.

If `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#defer(kotlin.Any)` is called while an animation is already in progress (i.e., `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#currentState()` != `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#defer(kotlin.Any)`), the animation will continue toward its current `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#defer(kotlin.Any)` while `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#pendingTargetState()` is set. This allows components to respond to the pending state early, potentially concurrently with the ongoing animation.

| Parameters |
|---|---|
| `targetState: S` | The state the transition should eventually animate to. |

## Public properties

### currentState

Cmn

```
open val currentState: S
```

Current state of the transition. If there is an active transition, `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/TransitionState#currentState()` and `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/TransitionState#targetState()` are different.

### pendingTargetState

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

```
val pendingTargetState: S?
```

The target state that the transition will eventually animate to once the deferred phase ends.

This value is set when `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#defer(kotlin.Any)` is called and cleared when `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#animateTo(kotlin.Any)` is called, at which point `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DeferredTransitionState#targetState()` will be updated to the new state.

### targetState

Cmn

```
open val targetState: S
```

Target state of the transition. If this is the same as `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/TransitionState#currentState()`, no transition is active.