Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent shadow clipping without adding content padding in Jetpack Compose

This question notes that in order to not clip the shadows on a LazyRow/LazyColumn in Jetpack Compose you need to add ContentPadding. However, I want to do the equivalent of "clipToPadding=false" without adding additional padding (the padding should be 0.dp). Is this possible? Or do you have to have some sort of 1.dp padding around the object?

Ex:

LazyRow(
        state = listState,
        flingBehavior = flingBehavior,
        contentPadding = PaddingValues(all = 0.dp)
    )

See clipping shadows on the lefthand edge:

like image 693
sepulchre01 Avatar asked Mar 17 '26 13:03

sepulchre01


1 Answers


LazyRow(
    state = listState,
    flingBehavior = flingBehavior,
    contentPadding = PaddingValues(horizontal = 0.dp)
) {
    items(itemsList) { item ->
        Box(
            modifier = Modifier
                .padding(horizontal = 8.dp) // add small padding to each item
                .drawWithContent {
                    drawContent() // draw the content
                    drawRect(
                        color = Color.Black, // define your shadow color
                        size = Size(size.width, 16f), // adjust shadow size
                        style = Shadow(style = ShadowStyle.Cut), // set the shadow style
                        shape = RectangleShape, // use a shape
                        topLeft = Offset(x = 0f, y = size.height - 16f) // set shadow offset
                    )
                }
        ) {
            // your content
        }
    }
}

like image 151
Darian-Cătălin Cucer Avatar answered Mar 20 '26 04:03

Darian-Cătălin Cucer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!