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
PagingState | The 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 page | the items |
| done, with no next page | the items, and the end of the list |
| failed on the next page | the items so far, and a next-page error with retry |
| failed on the first page or a refresh | the error with retry, and no items |
Wire it
- Kotlin
- Dart
// 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
PagingStateto it the same way:canLoadMore,retryTypeand the view state carry everything you need.