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

Steve C

09/25/2021, 9:20 PM
Hello everyone. Pretty new to working with compose, and I'm a bit stuck on animations. I've done quite a bit of searching, but I'm still stuck. I know I just don't know the proper syntax, but can't find a relevant example so I am reaching out for help here. Can anyone enlighten me on the correct way to use a different tween for different states? Here's what I have, but I get a compile error of "Not enough information to infer type variable T" if I put the tween call in a conditional:
Copy code
val transition = updateTransition(starState, label = "twinkle transition")

val alpha: State<Float> = transition.animateFloat(transitionSpec = {
    if (StarState.IDLE isTransitioningTo StarState.TWINKLE) {
        tween(durationMillis = 3000, easing = LinearOutSlowInEasing)
    } else {
        tween(durationMillis = 1500, easing = LinearOutSlowInEasing)
    }

    tween(durationMillis = 3000, easing = LinearOutSlowInEasing)
}, label = "alpha transition") { state ->
    if (state == StarState.TWINKLE) 1F else 0F
}
a

Albert Chang

09/26/2021, 1:49 AM
You need to specify
tween<Float>()
.
2 Views