:bug: Bug : Animation Issue :thread:
# compose-desktop
t
๐Ÿ› Bug : Animation Issue ๐Ÿงต
Why new animDuration not getting reflected? ๐Ÿค” What am I missing ? Code: https://gist.github.com/theapache64/96671be7b7ca459981180492dcff6c94
dynamic animDuration not supported? ๐Ÿค”
d
animate*AsState
is designed to only apply new
animationSpec
when
targetValue
changes. I'm curious what's your use case?
t
@Doris Liu I want the animDuration to be dynamic. my
targetValue
changes on button click, but new
animationSpec
not getting applied.
animateFloatAsState
takes initial
animationSpec
. Can u pls check the above attached code ? I think i miss something.. am new to compose animations
d
@theapache64 which compose version are you using? It's working just fine when I tried it with beta02 on Android - the animation is updated to whatever time I entered in the TextField
t
@Doris Liu am on Compose for Desktop ->
0.4.0-build174
d
Seems like a compose desktop specific issue. The code looks correct btw. ๐Ÿ™‚ Could you file a bug please?
t
Sure. thanks for checking
d
Actually, let me check on beta03 (not yet released), maybe desktop release is ahead of beta02.
t
Okay
d
yea, looks like it's an issue introduced recently (i.e. in beta03). ๐Ÿ˜… Thanks for letting me know
t
Ohh i see. alright. ๐Ÿ™‡ do i need to file it in jb-compose repo ?
d
t
d
Thank you! ๐Ÿ™
๐Ÿ‘ 1
k
I'm reviving this very old thread because I'm trying to do the exact same thing but for an
infiniteTransition
using the
animateFloat
method. Do you know if it is possible to have a dynamic animation duration in this case? I'm trying this and it's always using the initial duration.
Copy code
var animDuration by remember { mutableStateOf(2000) }
var tempAnimDuration by remember { mutableStateOf("2000") }


Column {
    val infiniteTransition = rememberInfiniteTransition()

    val alpha by infiniteTransition.animateFloat(
        initialValue = 0f,
        targetValue = 1f,
        animationSpec =
        infiniteRepeatable(
            animation = tween(
                durationMillis = animDuration,
                easing = LinearEasing
            ),
            repeatMode = RepeatMode.Restart
        )
    )


    Text(text = "Current Anim Duration is $animDuration")

    Box(
        modifier = Modifier
            .size(100.dp)
            .alpha(alpha)
            .background(Color.Red)
    )

    TextField(
        value = tempAnimDuration,
        onValueChange = { newAnimDuration ->
            tempAnimDuration = newAnimDuration
        }
    )

    Button(
        onClick = {
            try {
                animDuration = tempAnimDuration.toInt()
            } catch (e: NumberFormatException) {
                // skip
            }
        }
    ) {
        Text(text = "CHANGE ANIM DURATION to $tempAnimDuration && PLAY")
    }
}