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
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