bodo
01/18/2025, 8:32 PM@Composable
fun AnimatedScore(
currentScore: Int,
previousScore: Int,
) {
var score by remember { mutableIntStateOf(value = previousScore) }
AnimatedContent(
targetState = score
transitionSpec = {
val initialScore = initialState.toIntOrNull()
val targetScore = targetState.toIntOrNull()
Log.d("$initalScore -> $targetScore")
...
}
)
LaunchedEffect(currentScore, previousScore) {
delay(300)
score = currentScore
}
}
this composable is used in a viewholder of a recyclerview. and this viewholder is multiple times in one list. so as i get it right this composable will be recycled. and because of that i have the problem, that the animatedcontent composable has a wrong initial value form another recycled view.
can you please give me a hint how i can solve these issue.
so when previousScore != currentScore i want to animate the score from previousScore to currentScore.
thx a lotHendrik Pastunink
01/20/2025, 6:19 AMvar score by remember(previousScore) { mutableIntStateOf(value = previousScore) }
might work in this case. It will re-trigger the remember calculation anytime the previous score changesbodo
01/21/2025, 6:44 AM