Zoltan Demant
04/24/2025, 5:29 PMLazyColumn
? Either they...
• Scroll under the TopAppBar sad panda
• Or, if TopAppBar collapses, the sticky header will now... scroll underneath the statusBar instead sad panda
I feel like its a lose-lose situation:
• If I do some calculations to figure out when the sticky header is pinned at the top; and add Modifier.offset for it; theyre almost positioned correctly, but then theres a gap above them since its an offset and not padding.
• If I use padding instead, the whole list behaves strangely as the padding grows.
• If I add Modifier.padding (instead of using contentPadding) then that will account for my FAB (bottom padding) as well.
• Additionally.. when theres padding involved, there are some glitches where the sticky headers cut each other off at different breakpoints (I havent investigated this much though).
Does anyone know of a better way? I desperately need to use sticky headers for my use-case but feel like Im just chasing my own tail at this point.Pedro Lamarão
04/24/2025, 5:57 PMScaffold
?Zoltan Demant
04/24/2025, 6:07 PMPedro Lamarão
04/24/2025, 6:13 PMLazyColumn
with stickyHeaders
in a Scaffold
with a TopAppBar
works for me both for desktop and web. In my app there are layers between the scaffold and the list, I have not tested the list as a direct child of the scaffold.Zoltan Demant
04/25/2025, 3:14 AMIn my app there are layers between the scaffold and the list, I have not tested the list as a direct child of the scaffold.I think this is the reason why it works for you; at least Im assuming that you end up in a situation where you have Modifier.padding(x) applied to the container of / directly at the LazyColumn, and not passing padding into LazyColumn(contentPadding=x)?
Zoltan Demant
04/25/2025, 3:20 AMoriginal - top
, so I get :
LazyColumn(contentPadding = paddingWithoutTop, modifier = Modifier.padding(top = originalPadding.calculateTop)
Which is fine I guess, but seems very awkward to remember to do in every place where sticky headers are involved.Zoltan Demant
04/25/2025, 3:34 AM@JvmInline
private value class InsetPaddingValues(
private val original: PaddingValues,
) : PaddingValues by original {
override fun calculateTopPadding() = Zero
}
insetStickyHeaders: Boolean = false,
val finalPadding = if (insetStickyHeaders) InsetPaddingValues(padding) else padding
modifier.conditional(insetStickyHeaders) {
padding(top = padding.calculateTopPadding())
},
So basically just insetStickyHeaders=true and the LazyColumn is now padded at the top instead of its contents.Pedro Lamarão
04/27/2025, 3:03 PMTimo Drick
04/28/2025, 8:43 AMZoltan Demant
04/29/2025, 3:10 AMModifier.nestedScroll
.