Hi there, I'm playing with animations and I encoun...
# compose
j
Hi there, I'm playing with animations and I encountered a following problem: I have two texts and I'm animting their
fontSize
(pulse effect animation). I want an animation to be infinite, but I want to be able to restart an animation from default value when state changes. So basically I have a switch which determines which text should be animating, and when switch changes the animation should reset. As my animation is infinite I tried
rememberInfiniteTransition
, but there is no way to restart it (or I didn't find any). What would be the best approach for this problem? I would need something like
InfiniteTransition
but I don't want to remember it during state changes.
d
Could do something like this:
Copy code
val infiniteTransition = rememberInfiniteTransition()
        val fontSize by key(myState) {
            infiniteTransition.animateFloat(0f, 1f, infiniteRepeatable(
                tween(1000)
            ))
        }
When
myState
changes, the animation will be restarted
☝️ 1
🙏 1