ListKt

Added in 1.0.0-alpha01

public final class ListKt


Summary

Public methods

static final void
@Composable
VerticalList(
    @NonNull Modifier modifier,
    @NonNull ListState state,
    @NonNull PaddingValues contentPadding,
    boolean userScrollEnabled,
    OverscrollEffect overscrollEffect,
    boolean reverseLayout,
    @NonNull Alignment.Horizontal horizontalAlignment,
    @NonNull Arrangement.Vertical verticalArrangement,
    @NonNull Function1<@NonNull ListScopeUnit> content
)

This is a scrolling list component that only composes and lays out the currently visible items.

Public methods

VerticalList

@Composable
public static final void VerticalList(
    @NonNull Modifier modifier,
    @NonNull ListState state,
    @NonNull PaddingValues contentPadding,
    boolean userScrollEnabled,
    OverscrollEffect overscrollEffect,
    boolean reverseLayout,
    @NonNull Alignment.Horizontal horizontalAlignment,
    @NonNull Arrangement.Vertical verticalArrangement,
    @NonNull Function1<@NonNull ListScopeUnit> content
)

This is a scrolling list component that only composes and lays out the currently visible items. It is based on androidx.compose.foundation.lazy.LazyColumn, but with extra functionality and customized behavior required for Glimmer. Glimmer applications should always use VerticalList instead of LazyColumn to ensure correct behavior.

The content block defines a DSL which allows you to emit items of different types. For example you can use ListScope.item to add a single item and ListScope.items to add a list of items.

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.ui.unit.dp
import androidx.xr.glimmer.ListItem
import androidx.xr.glimmer.Text
import androidx.xr.glimmer.list.VerticalList

VerticalList(
    contentPadding = PaddingValues(16.dp),
    verticalArrangement = Arrangement.spacedBy(20.dp),
) {
    item { ListItem { Text("Header") } }
    items(count = 10) { index -> ListItem { Text("Item-$index") } }
    item { ListItem { Text("Footer") } }
}
Parameters
@NonNull Modifier modifier

the modifier to apply to this layout.

@NonNull ListState state

the state object to be used to control or observe the list's state.

@NonNull PaddingValues contentPadding

a padding around the whole content. This will add padding for the. content after it has been clipped, which is not possible via modifier param. You can use it to add a padding before the first item or after the last one.

boolean userScrollEnabled

If user gestures are enabled.

OverscrollEffect overscrollEffect

the OverscrollEffect that will be used to render overscroll for this layout. Note that the OverscrollEffect.node will be applied internally as well - you do not need to use Modifier.overscroll separately.

boolean reverseLayout

reverses the direction of scrolling and layout.

@NonNull Alignment.Horizontal horizontalAlignment

aligns items horizontally.

@NonNull Arrangement.Vertical verticalArrangement

is arrangement for items. This only applies if the content is smaller than the viewport.

@NonNull Function1<@NonNull ListScopeUnit> content

a block which describes the content. Inside this block you can use methods like ListScope.item to add a single item or ListScope.items to add a list of items.