Merge pull request #587 from InsanusMokrassar/0.25.8

0.25.8
This commit is contained in:
2025-06-17 15:47:54 +06:00
committed by GitHub
3 changed files with 49 additions and 9 deletions

View File

@@ -1,5 +1,12 @@
# Changelog
## 0.25.8
* `Pagination`:
* `Compose`:
* New function `rememberInfinityPagedComponentContext` to create `InfinityPagedComponentContext`
* New variants of `InfinityPagedComponent` component
## 0.25.7
* `Versions`:

View File

@@ -15,5 +15,5 @@ crypto_js_version=4.1.1
# Project data
group=dev.inmo
version=0.25.7
android_code_version=297
version=0.25.8
android_code_version=298

View File

@@ -65,6 +65,44 @@ class InfinityPagedComponentContext<T> internal constructor(
}
}
/**
* Creates and remembers an [InfinityPagedComponentContext] for managing infinite pagination in a Compose UI.
* This function is used to create a persistent pagination context that survives recompositions.
*
* @param size Number of items to load per page.
* @param page Initial page number to start pagination from (defaults to 0).
* @param scope [CoroutineScope] to launch pagination operations in. If not provided, a new scope will be created
* using [rememberCoroutineScope].
* @param loader Suspended function that loads paginated data. Receives the current pagination context and
* pagination parameters, and returns a [PaginationResult] containing the loaded data.
* @return An [InfinityPagedComponentContext] instance that manages the pagination state and operations.
*/
@Composable
fun <T> rememberInfinityPagedComponentContext(
size: Int,
page: Int = 0,
scope: CoroutineScope = rememberCoroutineScope(),
loader: suspend InfinityPagedComponentContext<T>.(Pagination) -> PaginationResult<T>
) = remember {
InfinityPagedComponentContext(page = page, size = size, scope = scope, loader = loader)
}
/**
* Composable function for managing an infinitely paged component.
*
* @param T The type of the paginated 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(
context: InfinityPagedComponentContext<T>,
block: @Composable InfinityPagedComponentContext<T>.(List<T>?) -> Unit
) {
val dataState = context.dataState.collectAsState()
context.block(dataState.value)
}
/**
* Composable function for managing an infinitely paged component.
*
@@ -84,13 +122,8 @@ internal fun <T> InfinityPagedComponent(
block: @Composable InfinityPagedComponentContext<T>.(List<T>?) -> Unit
) {
val scope = predefinedScope ?: rememberCoroutineScope()
val context = remember { InfinityPagedComponentContext<T>(page, size, scope, loader) }
remember {
context.reload()
}
val dataState = context.dataState.collectAsState()
context.block(dataState.value)
val context = rememberInfinityPagedComponentContext(page = page, size = size, scope = scope, loader = loader)
InfinityPagedComponent(context, block)
}
/**