Hi everyone. I have a composable where i want to a...
# compose
b
Hi everyone. I have a composable where i want to animate a score from one score to another (e.g. from 1 to 2)
Copy code
@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 lot
h
var score by remember(previousScore) { mutableIntStateOf(value = previousScore) }
might work in this case. It will re-trigger the remember calculation anytime the previous score changes
b
Good hint @Hendrik Pastunink . Thx