alexsullivan114
05/13/2021, 7:19 PMdata class Like(val count: Int)
And some composable that renders the like count:
@Composable
fun LikeText(like: Like) {
Text("${like.count}"
}
I want to trigger some animation if the like.count value has changed. How would I go about doing that?Kirill Grouchnikov
05/13/2021, 7:43 PMBox
with two Text
elements. One for the current count, and one for the "next" count. A tap / click triggers an animation that slides up the current count and slides up the next count. Then when the animation is done, you update the current count as well and "move" the texts back to the original places.Kirill Grouchnikov
05/13/2021, 7:44 PMalexsullivan114
05/13/2021, 7:44 PMDoris Liu
05/13/2021, 7:47 PMval transitionState = remember(count) { MutableTransitionState(initialState) }
transitionState.targetState = yourTargetState
// Create a transition going from the initial state of the "like" animation to the end
val transition = updateTransition(transitionState)
Kirill Grouchnikov
05/13/2021, 7:50 PMalexsullivan114
05/13/2021, 7:54 PMremember
to remember previous values of the count). Let me toy around with that, thank youalexsullivan114
05/13/2021, 7:55 PMKirill Grouchnikov
05/13/2021, 8:12 PMKirill Grouchnikov
05/13/2021, 8:13 PMalexsullivan114
05/13/2021, 8:19 PMremember
yields the first like count (so if it starts at 1 it looks like it'll always be 1). I know this is outside of the animation realm but what's the process to find out what the previous value of a composable parameter is?alexsullivan114
05/13/2021, 8:44 PMusePrevious
hook in React...Doris Liu
05/13/2021, 8:48 PMalexsullivan114
05/13/2021, 8:49 PMDoris Liu
05/13/2021, 8:54 PMalexsullivan114
05/13/2021, 8:55 PMDoris Liu
05/13/2021, 9:07 PMalexsullivan114
05/13/2021, 9:08 PMDoris Liu
05/13/2021, 9:10 PMAnimatedVisibility
features added in beta07, you could just keep a list of MutableTransitionState
and prune the list once both targetState
and currentState
have become false
. Unless you build against tip of tree androidx, you might have to wait a bit to use that feature.Doris Liu
05/13/2021, 9:12 PMalexsullivan114
05/13/2021, 9:18 PMalexsullivan114
05/13/2021, 9:27 PMDoris Liu
05/13/2021, 9:29 PMcurrentState
against targetState
, when they are the same, it means the transition has finished.Doris Liu
05/13/2021, 9:30 PMFlow
of currentState
change, but I think comparing the two states should give you what you need. 🙂alexsullivan114
05/13/2021, 9:35 PM