Skip to main content

Paging with Camouflage

Camouflage is the component library that Sinew's paging was designed to meet. CamoPagedList shows a list with every state of a paged load; sinew-camouflage maps Sinew's PagingState to it.

The mapping​

PagingStateThe list shows
loading the first page (Initial)a skeleton, with no items
loading a refresh (Refresh)a skeleton: a refresh drops the items
loading the next page (More)the items so far, and the next page loading
done, with a next pagethe items
done, with no next pagethe items, and the end of the list
failed on the next pagethe items so far, and a next-page error with retry
failed on the first page or a refreshthe error with retry, and no items

Wire it​

// sample: kotlin-lib/sample/shared/src/commonMain/kotlin/com/srctool/sinew/sample/OrderListScreen.kt#screen
@Composable
fun OrderListScreen(viewModel: OrderListViewModel) {
val state by viewModel.state.collectAsState()
LaunchedEffect(viewModel) { viewModel.onEvent(OrderListEvent.Opened) }
Column(Modifier.fillMaxSize().background(Camouflage.colors.surface).safeDrawingPadding()) {
CamoButton("Refresh", onClick = { viewModel.onEvent(OrderListEvent.Refreshed) }, modifier = Modifier.padding(8.dp))
CamoPagedList(
state = state.orders.toCamo(),
itemKey = { it.id },
onLoadMore = { viewModel.onEvent(OrderListEvent.EndReached) },
onRetry = { viewModel.onEvent(OrderListEvent.RetryTapped) },
onRefresh = { viewModel.onEvent(OrderListEvent.Refreshed) },
item = { order, _ -> CamoListItem(order.title, supporting = order.status) },
modifier = Modifier.weight(1f).testTag("orders"),
)
}
}

Good to know​

  • The error text is rendered while you build the UI, with the current language: a language switch updates it.
  • Without a localizer, a local message falls back to English.
  • This is the only place Sinew touches Camouflage. If you use another component library, map PagingState to it the same way: canLoadMore, retryType and the view state carry everything you need.