natario1
02/27/2021, 7:23 PMheight="wrap_content"
.Dominaezzz
02/27/2021, 7:36 PMAdam Powell
02/27/2021, 8:00 PMnatario1
02/27/2021, 8:10 PMAdam Powell
02/27/2021, 8:40 PMLazyColumn {
item { Header(...) }
items(...) { /* repeating items */ }
// etc.
}
natario1
03/01/2021, 11:39 AMArrangement.spacedBy(32.dp)
for top level elements, and Arrrangement.spacedBy(16.dp)
for inner lists. A different background, whatever. I know that I can just use Column, but still... The code also starts to look very weird IMO, as semantically what you have is "some headers, a list, a footer in a scrollable column" but what your code says is "a single list of mixed content".
It looks to me like compose still needs to provide a proper solution to this (I don't know how - maybe nested LazyColumns could communicate with root LazyColumn through locals and be flattened under the hood, maybe at least items
could accept modifiers and arrangement...)Nesting scrollable in the same direction layouts like ScrollableContainer and LazyColumn is not allowed. If you want to add a header before the list of items please take a look on LazyColumn component which has a DSL api which allows to first add a header via item() function and then the list of items via items().
)Adam Powell
03/01/2021, 3:07 PMLazyColumn(...) {
header(...)
header(...)
promotedItems(...)
searchResultItems(...)
footer(...)
}
natario1
03/01/2021, 3:47 PM@Composable fun LazyListScope.promotedItems()
works for splitting code in semantically reasonable sections, but the composable alone doesn't incapsulate all of the display logic! Like composables typically do. For example, it knows nothing about the spacing between items, controlled by `LazyColumn`'s arrangement, and any other LazyColumn
modifier prop.
So promotedItems()
might add spacing with spacers (which is already annoying), but then the caller LazyColumn defines more spacing through the arrangement and the UI is messed up. The result is that promotedItems()
is not really a reusable component - there's a hidden dependency with the parent modifier and props.
It's like LazyListScope.promotedItems()
is a RecyclerView.Adapter, who doesn't know about the RecyclerView background, decorations, padding, touch handling, none of this. This would be acceptable if there was a way to make this dependency explicit, e.g. pass stuff to promotedItems()
and then to items(modifier,...) { }
, but items has no modifier as we know.
About "variety of examples where the DSL style above isn't sufficient", if you want to start by collecting mine, basically everything that refers to the sublist as a whole is very tricky, impossible or a stretch. Think of giving the sublist (list minus header) a non-trivial background, for example. Padding, spacing, a click listener for the list as a whole...Adam Powell
03/01/2021, 3:58 PM