Compose Unstyled 2.0 is out! Check the official announcement blog ->
Class

DeferredTransitionState

A TransitionState that supports a deferred phase before the automatic transition begins.

Source set: Common
@ExperimentalDeferredTransitionApi
public class DeferredTransitionState<S>(initialState: S) : TransitionState<S>()

A 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 defer), the transition holds the new target as a pendingTargetState. The actual targetState remains unchanged, keeping the transition in its current visual state. Once animateTo is called, the pendingTargetState is cleared and the transition proceeds to the new targetState, triggering its automatic animations.

Parameters

initialState The initial state of the transition.

Properties

pendingTargetState

Source set: Common
public var pendingTargetState: S?

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

This value is set when defer is called and cleared when animateTo is called, at which point targetState will be updated to the new state.

Functions

defer

public fun defer(targetState: S)

Updates the pendingTargetState and initiates the deferred phase.

During this phase, the transition's targetState remains unchanged, keeping the transition in its current visual state. However, the new target is exposed via 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 animateTo.

If defer is called while an animation is already in progress (i.e., currentState != targetState), the animation will continue toward its current targetState while pendingTargetState is set. This allows components to respond to the pending state early, potentially concurrently with the ongoing animation.

Parameters

targetState The state the transition should eventually animate to.

animateTo

public fun animateTo(targetState: S)

Clears the pendingTargetState and updates the targetState to the provided targetState, ending the deferred phase and starting the automatic transition animation.

Note: The targetState provided here does not need to match the previous pendingTargetState. If a different state is provided, the transition will animate directly to this new state, bypassing the previously deferred target.

Parameters

targetState The final target state for the transition.

Last updated: