androidx.xr.glimmer.list

Interfaces

LazyListItemInfo

Contains useful information about an individual item in a VerticalList.

ListItemScope

Receiver scope being used by the item content parameter of VerticalList.

ListLayoutInfo

Information about the layout of the VerticalList.

ListScope

Receiver scope which is used by VerticalList.

Classes

ListState

A state object that can be hoisted to control and observe scrolling.

Objects

VerticalListDefaults

Contains the default values used by VerticalList.

Annotations

ListScopeMarker

DSL marker used to distinguish between list layout scope and the item scope.

Composables

VerticalList

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

rememberListState

Creates a ListState that is remembered across compositions.

Top-level functions summary

SnapLayoutInfoProvider

List snapping aligns the focus line with the center of the closest item.

Extension functions summary

inline Unit
<T : Any?> ListScope.items(
    items: List<T>,
    noinline key: ((item) -> Any)?,
    noinline contentType: (item) -> Any?,
    crossinline itemContent: @Composable ListItemScope.(item) -> Unit
)

Adds a list of items.

inline Unit
<T : Any?> ListScope.itemsIndexed(
    items: List<T>,
    noinline key: ((index: Int, item) -> Any)?,
    crossinline contentType: (index: Int, item) -> Any?,
    crossinline itemContent: @Composable ListItemScope.(index: Int, item) -> Unit
)

Adds a list of items where the content of an item is aware of its index.

Top-level functions

SnapLayoutInfoProvider

fun SnapLayoutInfoProvider(state: ListState): SnapLayoutInfoProvider

List snapping aligns the focus line with the center of the closest item. Combined with adaptive scrolling, this ensures that users have to move the same distance when swipes between items of the similar size, resulting in predictable movement.

Parameters
state: ListState

The ListState to observe for layout and focus information.

Returns
SnapLayoutInfoProvider

A focus-aware SnapLayoutInfoProvider instance.

Extension functions

ListScope.items

inline fun <T : Any?> ListScope.items(
    items: List<T>,
    noinline key: ((item) -> Any)? = null,
    noinline contentType: (item) -> Any? = { null },
    crossinline itemContent: @Composable ListItemScope.(item) -> Unit
): Unit

Adds a list of items.

Parameters
items: List<T>

the data list

noinline key: ((item) -> Any)? = null

a factory of stable and unique keys representing the item. Using the same key for multiple items in the list is not allowed. Type of the key should be saveable via Bundle on Android. If null is passed the position in the list will represent the key. When you specify the key the scroll position will be maintained based on the key, which means if you add/remove items before the current visible item the item with the given key will be kept as the first visible one. This can be overridden by calling 'requestScrollToItem' on the 'ListState'.

noinline contentType: (item) -> Any? = { null }

a factory of the content types for the item. The item compositions of the same type could be reused more efficiently. Note that null is a valid type and items of such type will be considered compatible.

crossinline itemContent: @Composable ListItemScope.(item) -> Unit

the content displayed by a single item

ListScope.itemsIndexed

inline fun <T : Any?> ListScope.itemsIndexed(
    items: List<T>,
    noinline key: ((index: Int, item) -> Any)? = null,
    crossinline contentType: (index: Int, item) -> Any? = { _, _ -> null },
    crossinline itemContent: @Composable ListItemScope.(index: Int, item) -> Unit
): Unit

Adds a list of items where the content of an item is aware of its index.

Parameters
items: List<T>

the data list

noinline key: ((index: Int, item) -> Any)? = null

a factory of stable and unique keys representing the item. Using the same key for multiple items in the list is not allowed. Type of the key should be saveable via Bundle on Android. If null is passed the position in the list will represent the key. When you specify the key the scroll position will be maintained based on the key, which means if you add/remove items before the current visible item the item with the given key will be kept as the first visible one. This can be overridden by calling 'requestScrollToItem' on the 'ListState'.

crossinline contentType: (index: Int, item) -> Any? = { _, _ -> null }

a factory of the content types for the item. The item compositions of the same type could be reused more efficiently. Note that null is a valid type and items of such type will be considered compatible.

crossinline itemContent: @Composable ListItemScope.(index: Int, item) -> Unit

the content displayed by a single item