ListKt

Added in 1.0.0-alpha06

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,
    @NonNull FlingBehavior flingBehavior,
    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.

static final void
@Composable
VerticalList(
    @Composable @NonNull Function0<Unit> title,
    @NonNull Modifier modifier,
    @NonNull ListState state,
    @NonNull PaddingValues contentPadding,
    boolean userScrollEnabled,
    OverscrollEffect overscrollEffect,
    @NonNull FlingBehavior flingBehavior,
    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,
    @NonNull FlingBehavior flingBehavior,
    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 Jetpack Compose Glimmer. Jetpack Compose 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.

See the other VerticalList overload for a variant with a title slot.

import androidx.xr.glimmer.ListItem
import androidx.xr.glimmer.Text
import androidx.xr.glimmer.list.VerticalList
import androidx.xr.glimmer.list.items

VerticalList {
    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.

@NonNull FlingBehavior flingBehavior

logic describing fling and snapping behavior when drag has finished.

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.

VerticalList

@Composable
public static final void VerticalList(
    @Composable @NonNull Function0<Unit> title,
    @NonNull Modifier modifier,
    @NonNull ListState state,
    @NonNull PaddingValues contentPadding,
    boolean userScrollEnabled,
    OverscrollEffect overscrollEffect,
    @NonNull FlingBehavior flingBehavior,
    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 Jetpack Compose Glimmer. Jetpack Compose 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.

This overload of VerticalList contains a title slot. The title is expected to be a androidx.xr.glimmer.TitleChip. It is positioned at the top center and visually overlaps the list content. The list is vertically offset to start from the title's vertical center. When the list is scrolled, the title remains static.

See the other VerticalList overload for a variant with no title slot.

import androidx.xr.glimmer.ListItem
import androidx.xr.glimmer.Text
import androidx.xr.glimmer.TitleChip
import androidx.xr.glimmer.list.VerticalList
import androidx.xr.glimmer.list.items

val ingredientItems =
    listOf("Milk", "Flour", "Egg", "Salt", "Apples", "Butter", "Vanilla", "Sugar", "Cinnamon")
VerticalList(title = { TitleChip { Text("Ingredients") } }) {
    items(ingredientItems) { text -> ListItem { Text(text) } }
}
Parameters
@Composable @NonNull Function0<Unit> title

a composable slot for the list title, expected to be a androidx.xr.glimmer.TitleChip. It overlaps the list, positioned at the top-center, and remains stuck to the top when the list is scrolled.

@NonNull Modifier modifier

applies to the layout that contains both list and title.

@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. The list is vertically offset to start from the title's vertical center, so custom content paddings must provide sufficient space to avoid content being obscured.

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.

@NonNull FlingBehavior flingBehavior

logic describing fling and snapping behavior when drag has finished.

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.