Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12141

Jetpack compose Lazy column with varying negative vertical arrangement

$
0
0

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.

@Composableprivate 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            )        }    }}

enter image description here

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?


Viewing all articles
Browse latest Browse all 12141

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>