-
-
Save Ahmed-Sellami/d8be81f8d8187043ee100f58f0a6a04f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ExperimentalAnimationApi | |
@Composable | |
fun ShoesCard(shoesArticle: ShoesArticle, onDeleted: () -> Unit) { | |
/* ... */ | |
val screenWidth: Int | |
with(LocalConfiguration.current) { | |
screenWidth = this.screenWidthDp | |
} | |
/* ... */ | |
val explosionPercentage = remember { mutableStateOf(0f) } | |
/* ... */ | |
funnelTranslation.value = (offsetX.value + funnelInitialTranslation).negateIfPositive { | |
explosionPercentage.value = (offsetX.value + funnelInitialTranslation) / screenWidth | |
} | |
Box { | |
/* ... */ | |
Canvas(modifier = Modifier | |
.height(itemHeightDp) | |
.offset { | |
IntOffset( | |
(offsetX.value.roundToInt() - 2 * particleRadius.toInt()).coerceAtMost( | |
funnelWidth.toInt() | |
), 0 | |
) | |
}) | |
{ | |
/* ... */ | |
repeat(numberOfExplosionParticles / 2 + 1) { | |
val hTranslation = (cos(angle).toFloat() * explosionRadius) * explosionPercentage.value | |
val vTranslation = (sin(angle).toFloat() * explosionRadius) * explosionPercentage.value | |
translate(hTranslation, vTranslation) { | |
drawCircle( | |
color = shoesArticle.color, | |
radius = explosionParticleRadius, | |
alpha = explosionPercentage.value / 2 | |
) | |
} | |
if (angle != 0.0 && angle != Math.PI) { | |
translate(hTranslation, -vTranslation) { | |
drawCircle( | |
color = shoesArticle.color, | |
radius = explosionParticleRadius, | |
alpha = explosionPercentage.value / 2 | |
) | |
} | |
} | |
angle += particleAngle | |
} | |
} | |
/* ... */ | |
} | |
/* ... */ | |
} | |
/* ... */ | |
private fun Float.negateIfPositive(onPositive: () -> Unit): Float { | |
return if (this > 0) { | |
onPositive() | |
-this | |
} else this | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment