I am trying to write a custom VerticalArragment fo...
# compose
i
I am trying to write a custom VerticalArragment for a lazyVerticalGrid where • items in the first line get a top padding of 10.dp • items in the seconds line get a top padding of 20.dp • and the rest will get a top padding of 5.dp
Copy code
object CustomVerticalArrangement : Arrangement.Vertical {

    override fun Density.arrange(totalSize: Int, sizes: IntArray, outPositions: IntArray) {
        var current = 0
        sizes.forEachIndexed { index, it ->
            when (abs(index / 3) {
                0 -> outPositions[index] = current + 10
                1 -> outPositions[index] = current + 20
                else -> outPositions[index] = current + 5
            }
            current += it
        }
    }
}
I pass it over later to my LazyVerticalGrid
Copy code
LazyVerticalGrid(
    modifier = Modifier.fillMaxSize(),
    columns = GridCells.Fixed(3),
    contentPadding = PaddingValues(start = 70.dp, end = 70.dp, top = 75.dp, bottom = 40.dp),
    // TODO: consider custom vertical arrangement
    verticalArrangement = CustomVerticalArrangement,
    horizontalArrangement = Arrangement.spacedBy(10.dp)
) { ... }
The code is never called I believe or it’s jus that LazyGrid doesn’t consider it and use the default spacing
0.dp
(debugger breakpoint never reached BTW) Am I doing something wrong or this is a bug?
i think this is intended! it looks like the LazyGrid composable only uses the
spacing
field in
Arrangement.Vertical
which will be
0.dp
by default.
Copy code
val spaceBetweenSlotsDp = if (isVertical) {
            horizontalArrangement?.spacing ?: 0.dp
        } else {
            verticalArrangement?.spacing ?: 0.dp
        }