Google is committed to advancing racial equity for Black communities. See how.

LazyPagingItems

class LazyPagingItems<T : Any>
kotlin.Any
   ↳ androidx.paging.compose.LazyPagingItems

The class responsible for accessing the data from a Flow of PagingData. In order to obtain an instance of LazyPagingItems use the collectAsLazyPagingItems extension method of Flow with PagingData. This instance can be used by the items and itemsIndexed methods inside LazyListScope to display data received from the Flow of PagingData.

Summary

Public methods
operator T?
get(index: Int)

Returns the item specified at index and notifies Paging of the item accessed in order to trigger any loads necessary to fulfill PagingConfig.prefetchDistance.

T?
peek(index: Int)

Returns the presented item at the specified position, without notifying Paging of the item access that would normally trigger page loads.

Unit

Refresh the data presented by this LazyPagingItems.

Unit

Retry any failed load requests that would result in a LoadState.Error update to this LazyPagingItems.

ItemSnapshotList<T>

Returns a new ItemSnapshotList representing the currently presented items, including any placeholders if they are enabled.

Properties
Int

The number of items which can be accessed.

CombinedLoadStates

A CombinedLoadStates object which represents the current loading state.

Public methods

get

operator fun get(index: Int): T?

Returns the item specified at index and notifies Paging of the item accessed in order to trigger any loads necessary to fulfill PagingConfig.prefetchDistance.

Parameters
index: Int the index of the item which should be returned.
Return
the item specified at index or null if the index is not between correct bounds or the item is a placeholder.

peek

fun peek(index: Int): T?

Returns the presented item at the specified position, without notifying Paging of the item access that would normally trigger page loads.

Parameters
index: Int Index of the presented item to return, including placeholders.
Return
The presented item at position index, null if it is a placeholder

refresh

fun refresh(): Unit

Refresh the data presented by this LazyPagingItems.

refresh triggers the creation of a new PagingData with a new instance of PagingSource to represent an updated snapshot of the backing dataset. If a RemoteMediator is set, calling refresh will also trigger a call to RemoteMediator.load with LoadType to allow RemoteMediator to check for updates to the dataset backing PagingSource.

Note: This API is intended for UI-driven refresh signals, such as swipe-to-refresh. Invalidation due repository-layer signals, such as DB-updates, should instead use PagingSource.invalidate.

retry

fun retry(): Unit

Retry any failed load requests that would result in a LoadState.Error update to this LazyPagingItems.

Unlike refresh, this does not invalidate PagingSource, it only retries failed loads within the same generation of PagingData.

LoadState.Error can be generated from two types of load requests:

snapshot

fun snapshot(): ItemSnapshotList<T>

Returns a new ItemSnapshotList representing the currently presented items, including any placeholders if they are enabled.

Properties

itemCount

val itemCount: Int

The number of items which can be accessed.

loadState

var loadState: CombinedLoadStates

A CombinedLoadStates object which represents the current loading state.