updateTransition
@Composable
public fun <T> updateTransition(targetState: T, label: String? = null): Transition<T>
This sets up a Transition
, and updates it with the target provided by targetState
. When
targetState
changes, Transition
will run all of its child animations towards their target
values specified for the new targetState
. Child animations can be dynamically added using
Transition.animateFloat
, animateColor
,
Transition.animateValue
, etc.
label
is used to differentiate different transitions in Android Studio.
Note: There is another rememberTransition
overload that accepts a MutableTransitionState
.
The difference between the two is that the MutableTransitionState
variant: 1) supports a
different initial state than target state (This would allow a transition to start as soon as it
enters composition.) 2) can be recreated to intentionally trigger a re-start of the transition.
Returns
a Transition object, to which animations can be added. |
Deprecated Use rememberTransition() instead
@Composable
public fun <T> updateTransition(
transitionState: MutableTransitionState<T>,
label: String? = null,
): Transition<T>
Creates a Transition
and puts it in the currentState
of
the provided transitionState
. Whenever the targetState
of
the transitionState
changes, the Transition
will animate to the new target state.
Remember: The provided transitionState
needs to be remember
ed.
Compared to the rememberTransition
variant 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 remember
ed, 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
: