From 24657b43beb400f997bb83a3940d2a63289820c0 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 3 Mar 2025 15:17:54 +0600 Subject: [PATCH] update InfinityPagedComponents --- .../src/commonMain/kotlin/InfinityPagedComponent.kt | 13 +++++++------ .../jvmTest/kotlin/InfinityPagedComponentTests.kt | 8 +++++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/pagination/compose/src/commonMain/kotlin/InfinityPagedComponent.kt b/pagination/compose/src/commonMain/kotlin/InfinityPagedComponent.kt index 44a0259252f..b94590f80e8 100644 --- a/pagination/compose/src/commonMain/kotlin/InfinityPagedComponent.kt +++ b/pagination/compose/src/commonMain/kotlin/InfinityPagedComponent.kt @@ -54,7 +54,8 @@ class InfinityPagedComponentContext 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 InfinityPagedComponent( @@ -74,9 +75,7 @@ internal fun InfinityPagedComponent( context.dataState.value = (context.dataState.value ?: emptyList()) + paginationResult.results } - context.dataState.value ?.let { - context.block(context.dataState.value) - } + context.block(context.dataState.value) } /** @@ -85,7 +84,8 @@ internal fun 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 InfinityPagedComponent( @@ -107,7 +107,8 @@ fun 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 InfinityPagedComponent( diff --git a/pagination/compose/src/jvmTest/kotlin/InfinityPagedComponentTests.kt b/pagination/compose/src/jvmTest/kotlin/InfinityPagedComponentTests.kt index 9844e0d400b..0dfb82a7fe8 100644 --- a/pagination/compose/src/jvmTest/kotlin/InfinityPagedComponentTests.kt +++ b/pagination/compose/src/jvmTest/kotlin/InfinityPagedComponentTests.kt @@ -29,7 +29,13 @@ class InfinityPagedComponentTests { } } ) { - assertEquals(expectedList, it) + 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()