Estou tentando criar um formulário para alterar a duração da animação. Conectei o ouvinte de cliques do DropdownMenu a animTime
e verifiquei que animTime
ele muda de 3000 para 300, mas a velocidade real da animação permanece a mesma.
Alguém sabe o que estou fazendo errado? org.jetbrains.compose:1.8.0-beta02
Se for o caso, estou usando.
@Composable
fun test() {
var animTime by remember { mutableIntStateOf(3000) }
var easing by remember { mutableStateOf(FastOutSlowInEasing) }
var containerSize by remember { mutableStateOf(IntSize.Zero) }
val boxSize = 100.dp
val moveX = max(0, containerSize.width - boxSize.px)
val moveOffset by animateIntOffsetAsState(
targetValue = IntOffset(moveX, 0),
animationSpec = infiniteRepeatable(
tween(
durationMillis = animTime,
easing = easing,
)
),
)
Row(
modifier = Modifier.fillMaxWidth()
) {
Column(
modifier = Modifier.weight(1f)
.background(Color.Red)
.onSizeChanged { containerSize = it }
) {
Box(
modifier = Modifier.size(boxSize)
.offset { moveOffset } // Offset must come before background (why?)
.background(Color.Cyan)
)
}
Column(Modifier.weight(1f)) {
Button(onClick = {
if (animTime == 3000) animTime /= 10
else animTime *= 10
}) {
Text("dur=$animTime")
}
}
}
}