吹爆代码,我想在动画结束时将值设置为 currentDegree,但是当我这样做时,它会重新组合。如何让它不重组?
@Composable
fun RotateImageCompose(width: Dp, height: Dp, resId: Int, targetDegree: Float) {
val currentDegree = remember { mutableStateOf(0f) }
var diff = currentDegree.value - targetDegree
.
.
.
val dregree by animateFloatAsState(targetValue = diff, animationSpec = tween(
easing = LinearEasing,
durationMillis = 180
), finishedListener = {
//this code cause the issue
currentDegree.value = it
})
Image(
painter = painterResource(id = resId),
contentDescription = null,
modifier = Modifier
.rotate(dregree)
.size(width, height)
)
}
答案 0 :(得分:0)
只需使用:
val currentDegree = remember {0f}
那样你的价值是不可变的。
请在此处查看详细说明:https://stackoverflow.com/a/66178263/5513788
答案 1 :(得分:0)
我将值保存在撰写之外