Skip to content

Instantly share code, notes, and snippets.

@Ahmed-Sellami
Created Sep 30, 2021
Embed
What would you like to do?
/* ... */
val leftParticlesRotation = remember { Animatable((Math.PI / 4).toFloat()) }
val rightParticlesRotation = remember { Animatable((Math.PI * 3 / 4).toFloat()) }
LaunchedEffect(isPlaced.value) {
if (isPlaced.value) {
launch {
leftParticlesRotation.animateTo(
targetValue = Math.PI.toFloat(),
animationSpec = tween(durationMillis = 400)
)
leftParticlesRotation.snapTo((Math.PI / 4).toFloat())
}
launch {
rightParticlesRotation.animateTo(
targetValue = 0f,
animationSpec = tween(durationMillis = 400)
)
rightParticlesRotation.snapTo((Math.PI * 3 / 4).toFloat())
if (currentIndex.value != destinationIndex.value) {
updateItemPosition(currentIndex.value, destinationIndex.value)
}
isPlaced.value = false
}
}
}
val leftParticles =
createParticles(leftParticlesRotation.value.toDouble(), shoesArticle.color, isLeft = true)
val rightParticles =
createParticles(rightParticlesRotation.value.toDouble(), shoesArticle.color, isLeft = false)
Box(/* ... */) {
Canvas(modifier = Modifier) {
leftParticles.forEach {
drawCircle(it.color, it.radius, center = IntOffset(it.x, it.y).toOffset())
}
}
Canvas(modifier = Modifier.align(Alignment.TopEnd)) {
rightParticles.forEach {
drawCircle(it.color, it.radius, center = IntOffset(it.x, it.y).toOffset())
}
}
/* ... */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment