Archie
02/01/2021, 6:40 AM@Composable
fun PoppingInCard() {
// Creates a transition state with an initial state where visible = false
val visibleState = remember { MutableTransitionState(false) }
// Sets the target state of the transition state to true. As it's different than the initial
// state, a transition from not visible to visible will be triggered.
visibleState.targetState = true
...
}
I was wondering whether doing:
visibleState.targetState = true
is fine? Like to create an "Intro Animation"? or is it better to put that inside a SideEffect
? or is there a better way?Doris Liu
02/01/2021, 7:46 AMvisibleState.targetState = true
is perfectly fine. You can even do a val visibleState = remember { MutableTransitionState(false).apply{ targetState = true } }
if you never intend to change the targetState
again. 🙂Archie
02/01/2021, 7:58 AMDoris Liu
02/01/2021, 8:01 AMArchie
02/01/2021, 8:21 AMDoris Liu
02/02/2021, 2:51 AMMutableTransitionState
. I suspect it won't work well if you scroll away during the animation, because MutableTransitionState.currentState
doesn't change until the animation is finished. So when you scroll back, the animation will restart from the beginning. This is a good feature request. 🙂Archie
02/02/2021, 4:32 AMDoris Liu
02/02/2021, 4:43 AMMutableTransitionState
is recommended way to go for enter animation using Transition
.Archie
02/02/2021, 4:45 AMDoris Liu
02/02/2021, 4:50 AMArchie
02/02/2021, 11:32 AMDoris Liu
02/03/2021, 1:30 AMlaunch
a new coroutine to animate the offset of the container when you need it to shake. My recommendation is using Animatable.animateTo
with either keyframes
, or an initial velocity + a high bouncy spring
. 🙂Archie
02/03/2021, 4:49 AMoffsetAnim.animateTo(IntOffset(10))
// then immediately set it back to 0
offsetAnim.animateTo(IntOffset.ZERO)
is this correct? or is there a better way in the existing api? (Im really sorry if this was a stupid question)Doris Liu
02/03/2021, 5:00 AMAnimationSpec
. You could do something like:
// Assuming offset is Animatable<Dp>
offset.animateTo(0.dp, keyframes<Dp> {
durationMillis = 300
0.dp at 0
80.dp at 100
-30.dp at 200
0.dp at 300
}
Archie
02/03/2021, 5:16 AMspring
" Sorry about that... thank you very much :DMutableTransitionState
over MutableState
+ updateTransition(mutableState)
??
Also is there a way to do Transition
based on a composable size? for example translating a composable based on it size.. I would like to have a similar effect to AnimatedVisibility
's slideInHorizontally()
where it could translate the whole composable's based on it width.Doris Liu
02/10/2021, 5:37 AMIs there an important difference between usingRight now the difference isoverMutableTransitionState
+MutableState
??updateTransition(mutableState)
MutableTransitionState
1) allows an initial state different than the first target state. 2) can be intentionally recreated to tigger the re-creation of the transition animation (i.e. forcing it to restart).
Also is there a way to doNot at the moment, but it's high on my feature list. 😄based on a composable size? for example translating a composable based on it size.. I would like to have a similar effect toTransition
'sAnimatedVisibility
where it could translate the whole composable's based on it width.slideInHorizontally()
Archie
02/10/2021, 5:38 AMDoris Liu
02/18/2021, 8:36 PMArchie
02/19/2021, 2:44 AMDoris Liu
02/19/2021, 3:04 AMArchie
02/19/2021, 3:14 AMDoris Liu
02/19/2021, 3:30 AMI'll try to create a small sample since I can't share the whole code as its company code but ill try to replicate the usecase in a smaller project.Sounds good.
I really appreciate your replies. Thank you very much. I hope I am not wasting too much of your time.No worries. 🙂
Archie
02/19/2021, 5:34 AMDoris Liu
02/21/2021, 3:13 AMArchie
02/21/2021, 7:07 AM