https://kotlinlang.org logo
#compose
Title
# compose
s

Sheroz Nazhmudinov

05/01/2020, 12:14 PM
Hey, i was trying out
Transition
in Compose, and had couple of questions. First is about
transitionDefinition
- i see that it’s an equivalent of value animator (correct me if i’m wrong). Is there a way to set the duration to it, and delay before the start? Second is about the
Transition
composable - is there a way to start the transition based on the user event (e.g., click)? Any hints/suggestions would be appreciated! 🙂
z

Zach Klippenstein (he/him) [MOD]

05/01/2020, 1:49 PM
This article has examples of the various animation builders - there are a few that let you specify duration: https://proandroiddev.com/animations-in-jetpack-compose-using-transition-25d5d2143401 You can look at the API reference for more information: https://developer.android.com/reference/kotlin/androidx/animation/TweenBuilder Transition animations are controlled by state changes, so to start an animation on a click, your click handler should change some state (e.g in a
@Model
or a
state {}
. There are lots of examples of this in the framework, take a look at the implementation of any UI control that animates itself (eg.
Modifier.ripple
, radio buttons, I think Slider might use them).
s

Sheroz Nazhmudinov

05/01/2020, 2:19 PM
thanks i’ve check the medium article before that. I was trying to use
angle using tween
as specified in the article, but
angle
gets highlighted as an unresolved reference. Have you tried it before?
k

Kazemihabib1996

05/01/2020, 2:21 PM
did you try:
private val angle = FloatPropKey()
👍 1
s

Sheroz Nazhmudinov

05/01/2020, 2:22 PM
thanks that worked! 👍
👍 1
2 Views