Skip to content

Instantly share code, notes, and snippets.

@Ahmed-Sellami
Created September 30, 2021 21:17
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/7c59f09c3a5cf93e312cbaad718fc15c to your computer and use it in GitHub Desktop.
Save Ahmed-Sellami/7c59f09c3a5cf93e312cbaad718fc15c to your computer and use it in GitHub Desktop.
private val particlesStreamRadii = mutableListOf<Float>()
private var itemHeight = 0
private var particleRadius = 0f
private var slotItemDifference = 0f
@ExperimentalAnimationApi
@Composable
fun ShoesCard(
shoesArticle: ShoesArticle,
slideState: SlideState,
shoesArticles: MutableList<ShoesArticle>,
updateSlideState: (shoesArticle: ShoesArticle, slideState: SlideState) -> Unit,
updateItemPosition: (currentIndex: Int, destinationIndex: Int) -> Unit
) {
val itemHeightDp = dimensionResource(id = R.dimen.image_size)
val slotPaddingDp = dimensionResource(id = R.dimen.slot_padding)
with(LocalDensity.current) {
itemHeight = itemHeightDp.toPx().toInt()
particleRadius = dimensionResource(id = R.dimen.particle_radius).toPx()
if (particlesStreamRadii.isEmpty())
particlesStreamRadii.addAll(arrayOf(6.dp.toPx(), 10.dp.toPx(), 14.dp.toPx()))
slotItemDifference = 18.dp.toPx()
}
/* ... */
}
private fun createParticles(rotation: Double, color: Color, isLeft: Boolean): List<Particle> {
val particles = mutableListOf<Particle>()
for (i in 0 until particlesStreamRadii.size) {
val currentParticleRadius = particleRadius * (i + 1) / particlesStreamRadii.size
val verticalOffset =
(itemHeight.toFloat() - particlesStreamRadii[i] - slotItemDifference + currentParticleRadius).toInt()
val horizontalOffset = currentParticleRadius.toInt()
particles.add(
Particle(
color = color.copy(alpha = (i + 1) / (particlesStreamRadii.size).toFloat()),
x = (particlesStreamRadii[i] * cos(rotation)).toInt() + if (isLeft) horizontalOffset else -horizontalOffset,
y = (particlesStreamRadii[i] * sin(rotation)).toInt() + verticalOffset,
radius = currentParticleRadius
)
)
}
return particles
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment