theapache64
03/20/2021, 7:57 PMtheapache64
03/20/2021, 7:58 PMtheapache64
03/20/2021, 8:01 PMDoris Liu
03/20/2021, 8:16 PManimate*AsState
is designed to only apply new animationSpec
when targetValue
changes. I'm curious what's your use case?theapache64
03/20/2021, 8:19 PMtargetValue
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 animationsDoris Liu
03/20/2021, 9:30 PMtheapache64
03/20/2021, 9:31 PM0.4.0-build174
Doris Liu
03/20/2021, 9:33 PMtheapache64
03/20/2021, 9:33 PMDoris Liu
03/20/2021, 9:35 PMtheapache64
03/20/2021, 9:35 PMDoris Liu
03/20/2021, 9:39 PMtheapache64
03/20/2021, 9:40 PMDoris Liu
03/20/2021, 9:41 PMtheapache64
03/20/2021, 9:46 PMDoris Liu
03/20/2021, 9:46 PMKimon
01/29/2024, 2:00 PMinfiniteTransition
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.Kimon
01/29/2024, 2:07 PMvar 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")
}
}