rememberTransition
@ExperimentalDeferredTransitionApi
@Composable
public fun <T> rememberTransition(
transitionState: DeferredTransitionState<T>,
label: String? = null,
): DeferredTransition<T>
Creates and remembers a DeferredTransition for a given DeferredTransitionState.
A DeferredTransition allows for a two-stage state update:
- Deferred Phase: Initiated by DeferredTransitionState.defer. The transition's
targetStateremains unchanged, while the new target is exposed viapendingTargetState. This allows higher-level components to implement custom behavior (e.g., manual gesture tracking) while the automatic transition is "held". - Automatic Phase: Initiated by DeferredTransitionState.animateTo. The
pendingTargetStateis cleared andtargetStateis updated, starting the automatic transition animations.
Parameters
| transitionState | The DeferredTransitionState that manages the current and target states. |
| label | An optional label for the transition to be displayed in Android Studio's Animation Preview. |
Returns
| A DeferredTransition that will update whenever transitionState changes. |
rememberTransition
@Composable
public fun <T> rememberTransition(
transitionState: TransitionState<T>,
label: String? = null,
): Transition<T>
Creates a Transition and puts it in the currentState of the provided transitionState. If the TransitionState.targetState changes, the Transition will change where it will animate to.
Remember: The provided transitionState needs to be remembered.
Compared to updateTransition that takes a targetState, this function supports a different initial state than the first targetState. Here is an example:
In most cases, it is recommended to reuse the same transitionState that is remembered, such that Transition preserves continuity when targetState is changed. However, in some rare cases it is more critical to immediately snap to a state change (e.g. in response to a user interaction). This can be achieved by creating a new transitionState: