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.

Top-level functions summary

Unit
@Composable
VerticalList(
    modifier: Modifier,
    state: ListState,
    contentPadding: PaddingValues,
    userScrollEnabled: Boolean,
    overscrollEffect: OverscrollEffect?,
    reverseLayout: Boolean,
    horizontalAlignment: Alignment.Horizontal,
    verticalArrangement: Arrangement.Vertical,
    content: ListScope.() -> Unit
)

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

ListState
@Composable
rememberListState(
    initialFirstVisibleItemIndex: Int,
    initialFirstVisibleItemScrollOffset: Int
)

Creates a ListState that is remembered across compositions.

Top-level functions

VerticalList

@Composable
fun VerticalList(
    modifier: Modifier = Modifier,
    state: ListState = rememberListState(),
    contentPadding: PaddingValues = PaddingValues(0.dp),
    userScrollEnabled: Boolean = true,
    overscrollEffect: OverscrollEffect? = rememberOverscrollEffect(),
    reverseLayout: Boolean = false,
    horizontalAlignment: Alignment.Horizontal = Alignment.Start,
    verticalArrangement: Arrangement.Vertical = Arrangement.Top,
    content: ListScope.() -> Unit
): Unit

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
modifier: Modifier = Modifier

the modifier to apply to this layout.

state: ListState = rememberListState()

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

contentPadding: PaddingValues = PaddingValues(0.dp)

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.

userScrollEnabled: Boolean = true

If user gestures are enabled.

overscrollEffect: OverscrollEffect? = rememberOverscrollEffect()

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.

reverseLayout: Boolean = false

reverses the direction of scrolling and layout.

horizontalAlignment: Alignment.Horizontal = Alignment.Start

aligns items horizontally.

verticalArrangement: Arrangement.Vertical = Arrangement.Top

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

content: ListScope.() -> Unit

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.

rememberListState

@Composable
fun rememberListState(
    initialFirstVisibleItemIndex: Int = 0,
    initialFirstVisibleItemScrollOffset: Int = 0
): ListState

Creates a ListState that is remembered across compositions.

Changes to the provided initial values will not result in the state being recreated or changed in any way if it has already been created.

Parameters
initialFirstVisibleItemIndex: Int = 0

the initial value for ListState.firstVisibleItemIndex

initialFirstVisibleItemScrollOffset: Int = 0

the initial value for ListState.firstVisibleItemScrollOffset