PaginatedState
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
every item loaded so far, in order, across all the pages fetched.
where the loading stands, first page and next page separately.
Properties
There is another page to fetch. Drive PaginatedResource.loadNextPage off this as the user nears the end of the list; it is false while the next page is in flight, so it will not ask twice. It also reads true while the first page is loading, a call PaginatedResource.loadNextPage ignores.
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.
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.
The list has nothing yet and is fetching its first page — show a skeleton or a spinner over the whole screen.