:sparkles: Animation API As per my understanding,...
# compose
t
Animation API As per my understanding,
MutableTransitionState
(MTS) with
updateTransition
is only useful if we want to update the state within the composable. If we simply want to access the
MTS#currentState
,
MTS#targetState
and
MTS#isIdle
, we can use
Transition#currentState
,
Transition#targetState
and
Transition#isRunning
respectively. Please correct me if am wrong.
In other words, is it okay to use
transition
object inside
animationSpec
like this?
d
Actually
MutableTransitionState
can be created and accessed from anywhere such as your ViewModel, whereas
updateTransition
can only be invoked from composition. Here's an example of creating & manipulating
MutableTransitionState
from outside of composition: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]se/animation/demos/AnimatedVisiblilityLazyColumnDemo.kt;l=115 It's best to read
initialState
&
targetState
in
transitionSpec
from the receiver AnimatedContentScope (which is an impl of Transition.Segment), instead of from the Transition directly. When seeking Transitions (e.g. for animation tooling), we'll be creating new
Transition.Segment
for the specific initial/target required by seeking, and call
Transition.Segment.transitionSpec()
to obtain the animations used in that segment. There's no guarantee that the Segment.initialState is always the same as Transition.currentState.
t
Understood 👍
d
We should probably include that in the documentation. 🙂 BTW, aside from MTS allowing instantiation outside of composition,
MTS#targetState/currentState
are the same as
Transition#targetState/currentState
.
👍 2