Skip to content

Instantly share code, notes, and snippets.

@Ahmed-Sellami
Last active September 19, 2021 15:03
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/d8be81f8d8187043ee100f58f0a6a04f to your computer and use it in GitHub Desktop.
Save Ahmed-Sellami/d8be81f8d8187043ee100f58f0a6a04f to your computer and use it in GitHub Desktop.
@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