sindrenm
10/11/2024, 10:13 AMsindrenm
10/11/2024, 10:13 AM@Composable
fun EagerListSample(contentPadding: PaddingValues) {
Column(
modifier = Modifier
.verticalScroll(rememberScrollState())
.padding(contentPadding),
verticalArrangement = Arrangement.spacedBy(16.dp),
) {
if (favoritesSection.any()) {
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
Header("Favorite Items")
Column {
favoritesSection.forEach { item -> Item(item) }
}
}
}
if (everythingSection.any()) {
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
Header("All Items")
Column {
everythingSection.forEach { item -> Item(item) }
}
}
}
}
}
sindrenm
10/11/2024, 10:17 AM@Composable
fun LazyListSample(contentPadding: PaddingValues) {
LazyColumn(contentPadding = contentPadding) {
if (favoritesSection.any()) {
item { Header("Favorite Items", Modifier.padding(bottom = 8.dp)) }
items(favoritesSection) { item -> Item(item) }
}
if (everythingSection.any()) {
item {
// This feels dirty
val modifier = if (favoritesSection.any()) Modifier.padding(top = 16.dp) else Modifier
Header("All Items", modifier.padding(bottom = 8.dp))
}
items(everythingSection) { item -> Item(item) }
}
}
}
sindrenm
10/11/2024, 10:19 AM@Composable
fun LazyListSample(contentPadding: PaddingValues) {
LazyColumn(contentPadding = contentPadding) {
if (favoritesSection.any()) {
item { Header("Favorite Items", Modifier.padding(bottom = 8.dp)) }
items(favoritesSection) { item -> Item(item) }
}
if (everythingSection.any()) {
if (favoritesSection.any()) {
item { Spacer(Modifier.height(16.dp)) }
}
item { Header("All Items", Modifier.padding(bottom = 8.dp)) }
items(everythingSection) { item -> Item(item) }
}
}
}
sindrenm
10/11/2024, 10:39 AMfun LazyListScope.group(
verticalArrangement: Arrangement.Vertical,
content: LazyListScope.() -> Unit,
) {
// ...
}
fun LazyListScope.group(
horizontalArrangement: Arrangement.Horizontal,
content: LazyListScope.() -> Unit,
) {
// ...
}
@Composable
fun LazyListSample(contentPadding: PaddingValues) {
LazyColumn(
contentPadding = contentPadding,
verticalArrangement = Arrangement.spacedBy(16.dp),
) {
if (favoritesSection.any()) {
group(verticalArrangement = Arrangement.spacedBy(8.dp)) {
item { Header("Favorite Items", Modifier.padding(bottom = 8.dp)) }
group(verticalArrangement = Arrangement.Top) {
items(favoritesSection) { item -> Item(item) }
}
}
}
if (everythingSection.any()) {
group(verticalArrangement = Arrangement.spacedBy(8.dp)) {
item { Header("All Items", Modifier.padding(bottom = 8.dp)) }
group(verticalArrangement = Arrangement.Top) {
items(everythingSection) { item -> Item(item) }
}
}
}
}
}
sindrenm
10/11/2024, 10:51 AMfun LazyListScope.spaced(
itemSpacing: Dp,
content: LazyListScope.() -> Unit,
) {
content()
}
@Composable
fun LazyListSample(contentPadding: PaddingValues) {
LazyColumn(contentPadding = contentPadding) {
spaced(16.dp) {
if (favoritesSection.any()) {
spaced(8.dp) {
item { Header("Favorite Items", Modifier.padding(bottom = 8.dp)) }
spaced(0.dp) {
items(favoritesSection) { item -> Item(item) }
}
}
}
if (everythingSection.any()) {
spaced(8.dp) {
item { Header("All Items", Modifier.padding(bottom = 8.dp)) }
spaced(0.dp) {
items(everythingSection) { item -> Item(item) }
}
}
}
}
}
}
However, supporting any arrangement would probably make more sense in a public API.