update InfinityPagedComponents

This commit is contained in:
2025-03-03 15:17:54 +06:00
parent 659d3b6fa5
commit 24657b43be
2 changed files with 14 additions and 7 deletions

View File

@@ -54,7 +54,8 @@ class InfinityPagedComponentContext<T> internal constructor(
* @param page Initial page number.
* @param size Number of items per page.
* @param loader Suspended function that loads paginated data.
* @param block Composable function that renders the UI with the loaded data.
* @param block Composable function that renders the UI with the loaded data. When data is in loading state, block will
* receive null as `it` parameter
*/
@Composable
internal fun <T> InfinityPagedComponent(
@@ -74,9 +75,7 @@ internal fun <T> InfinityPagedComponent(
context.dataState.value = (context.dataState.value ?: emptyList()) + paginationResult.results
}
context.dataState.value ?.let {
context.block(context.dataState.value)
}
}
/**
@@ -85,7 +84,8 @@ internal fun <T> InfinityPagedComponent(
* @param T The type of the paginated data.
* @param pageInfo Initial pagination information.
* @param loader Suspended function that loads paginated data.
* @param block Composable function that renders the UI with the loaded data.
* @param block Composable function that renders the UI with the loaded data. When data is in loading state, block will
* receive null as `it` parameter
*/
@Composable
fun <T> InfinityPagedComponent(
@@ -107,7 +107,8 @@ fun <T> InfinityPagedComponent(
* @param T The type of the paginated data.
* @param size Number of items per page.
* @param loader Suspended function that loads paginated data.
* @param block Composable function that renders the UI with the loaded data.
* @param block Composable function that renders the UI with the loaded data. When data is in loading state, block will
* receive null as `it` parameter
*/
@Composable
fun <T> InfinityPagedComponent(

View File

@@ -29,7 +29,13 @@ class InfinityPagedComponentTests {
}
}
) {
if (it == null) {
if (this.iterationState.value.second != null) {
assertEquals(0, (this.iterationState.value.second as? SimplePagination) ?.page)
}
} else {
assertEquals(expectedList, it)
}
LaunchedEffect(it ?.size) {
loadNext()