#composethinking Paddings - which approach is bett...
# compose
w
#composethinking Paddings - which approach is better in your opinion with LazyColumn and why?
listOfSomething: List<Something>
1️⃣
Copy code
Scaffold(
    ...
} { contentPadding ->
    LazyColumn(
        contentPadding = contentPadding,
    ) {
        items(listOfSomething) { something ->
            SomeItem(something)
        }
        item {
            Spacer(Modifier.height(24.dp))
        }
    }
)
2️⃣
Copy code
Scaffold(
    ...
} { contentPadding ->
    LazyColumn(
        contentPadding = contentPadding + PaddingValues(bottom = 24.dp),
    ) {
        items(listOfSomething) { something ->
            SomeItem(something)
        }
    }
}
This 2nd approach can be implemented by custom
PaddingValues
extension:
Copy code
operator fun PaddingValues.plus(other: PaddingValues) = PaddingValues(
    start = this.start + other.start,
    top = <http://this.top|this.top> + <http://other.top|other.top>,
    end = this.end + other.end,
    bottom = this.bottom + other.bottom,
)

private val PaddingValues.start get() = calculateStartPadding(LayoutDirection.Ltr)
private val <http://PaddingValues.top|PaddingValues.top> get() = calculateTopPadding()
private val PaddingValues.end get() = calculateEndPadding(LayoutDirection.Ltr)
private val PaddingValues.bottom get() = calculateBottomPadding()
This
PaddingValues
extension will be useful with globally defined paddings like
Copy code
val ScrollableContentPaddingVertical = PaddingValues(vertical = 24.dp)
Then we could use simple
Copy code
contentPadding = contentPadding + ScrollableContentPaddingVertical
in place of top and bottom spacers