PaginatedState

data class PaginatedState<out T>(val items: List<T>, val loadStates: PaginatedLoadStates)

Everything a paginated list needs to draw itself: the items loaded so far, and what the loading is doing.

Emitted by PaginatedResource.state. The four extension properties below — isInitialLoading, isEmpty, initialError, canLoadMore — cover the states a list screen actually branches on; reach into loadStates only for something they do not answer.

when {
state.isInitialLoading -> Skeleton()
state.initialError != null -> ErrorScreen(state.initialError!!)
state.isEmpty -> EmptyScreen()
else -> List(state.items, canLoadMore = state.canLoadMore)
}

Parameters

items

every item loaded so far, in order, across all the pages fetched.

loadStates

where the loading stands, first page and next page separately.

Constructors

Link copied to clipboard
constructor(items: List<T>, loadStates: PaginatedLoadStates)

Properties

Link copied to clipboard

There is another page to fetch. Drive PaginatedResource.loadNextPage off this as the user nears the end of the list; it is false while a page is already in flight, so it will not ask twice.

Link copied to clipboard

The error to show over the whole screen: set only when the list failed with nothing to display. A failure that still has items behind it stays null here — surface that one in place, without taking the list away.

Link copied to clipboard

The list came back with nothing — show an empty state, not an error. false while the first page is still loading and while it is in error, so it never flashes before the real answer.

Link copied to clipboard

The list has nothing yet and is fetching its first page — show a skeleton or a spinner over the whole screen.

Link copied to clipboard
val items: List<T>
Link copied to clipboard