I am implementing a Lazycolumn
to display gift cards in a stacked manner. Similar to the Samsung wallet.
data class GiftCard(
val giftCardUrl: String = "https://via.placeholder.com/150",
val color: Color = Color.Green,
val giftCardCode: String = color.hashCode().toString(),
) {
fun isSameKindAs(other: GiftCard): Boolean {
return giftCardCode == other.giftCardCode
}
}
The same gift cards are stacked together (overlapping) with 10.dp
padding in between. If the upcoming car a different, then the overlapping padding becomes 30.dp
.
@Composable
private fun StackedGiftCards(
giftCards: List<GiftCard>,
) {
val cardWidth = 343.dp
val cardHeight = 219.dp
LazyColumn(
modifier = Modifier
.fillMaxSize(),
verticalArrangement = Arrangement.spacedBy(10.dp - cardHeight)
) {
itemsIndexed(giftCards) { index, giftCard ->
val paddingTop = when {
index == 0 -> {
0.dp
}
!giftCard.isSameKindAs(giftCards[index - 1]) -> {
30.dp
}
else -> {
0.dp
}
}
GiftCard(
modifier = Modifier
.width(cardWidth)
.height(cardHeight)
.padding(
top = paddingTop
),
giftCard = giftCard,
index = index
)
}
}
}
Unfortunately, a LazyColumn
only allows a single vertical arrangement of unique spacing.
Does compose allow this at all? Can someone shed some light on this?