Skip to content

Instantly share code, notes, and snippets.

@Ahmed-Sellami
Created September 30, 2021 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ahmed-Sellami/eed2b9ce9ef62e017a79e44d8478e230 to your computer and use it in GitHub Desktop.
Save Ahmed-Sellami/eed2b9ce9ef62e017a79e44d8478e230 to your computer and use it in GitHub Desktop.
/* ... */
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