mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-09-06 00:29:57 +00:00
add KDocs for InfinityPagedComponentContext and PagedComponent
This commit is contained in:
@@ -3,20 +3,36 @@ package dev.inmo.micro_utils.pagination.compose
|
||||
import androidx.compose.runtime.*
|
||||
import dev.inmo.micro_utils.pagination.*
|
||||
|
||||
/**
|
||||
* Context for managing infinite pagination in a Compose UI.
|
||||
*
|
||||
* @param T The type of the data being paginated.
|
||||
* @property iterationState Holds the current pagination state and iteration count.
|
||||
* @property dataState Stores the loaded data, initially null.
|
||||
* @constructor Internal constructor to initialize pagination.
|
||||
* @param page Initial page number.
|
||||
* @param size Number of items per page.
|
||||
*/
|
||||
class InfinityPagedComponentContext<T> internal constructor(
|
||||
page: Int,
|
||||
size: Int
|
||||
) {
|
||||
internal val iterationState: MutableState<Pair<Int, Pagination>> = mutableStateOf(0 to SimplePagination(page, size))
|
||||
|
||||
internal val dataState: MutableState<List<T>?> = mutableStateOf(null)
|
||||
|
||||
/**
|
||||
* Loads the next page of data. If the current page is the last one, the function returns early.
|
||||
*/
|
||||
fun loadNext() {
|
||||
iterationState.value = iterationState.value.let {
|
||||
if ((dataState.value as? PaginationResult<*>) ?.isLastPage == true) return
|
||||
(it.first + 1) to it.second.nextPage()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the pagination from the first page, clearing previously loaded data.
|
||||
*/
|
||||
fun reload() {
|
||||
dataState.value = null
|
||||
iterationState.value = iterationState.value.let {
|
||||
@@ -25,6 +41,15 @@ class InfinityPagedComponentContext<T> internal constructor(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Composable function for managing an infinitely paged component.
|
||||
*
|
||||
* @param T The type of the paginated data.
|
||||
* @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.
|
||||
*/
|
||||
@Composable
|
||||
internal fun <T> InfinityPagedComponent(
|
||||
page: Int,
|
||||
@@ -43,6 +68,14 @@ internal fun <T> InfinityPagedComponent(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloaded composable function for an infinitely paged component.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
@Composable
|
||||
fun <T> InfinityPagedComponent(
|
||||
pageInfo: Pagination,
|
||||
@@ -58,6 +91,15 @@ fun <T> InfinityPagedComponent(
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloaded composable function for an infinitely paged component.
|
||||
*
|
||||
* @param T The type of the paginated data.
|
||||
* @param initialPage 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.
|
||||
*/
|
||||
@Composable
|
||||
fun <T> InfinityPagedComponent(
|
||||
initialPage: Int,
|
||||
@@ -68,6 +110,14 @@ fun <T> InfinityPagedComponent(
|
||||
PagedComponent(null, initialPage, size, loader, block)
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloaded composable function for an infinitely paged component.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
@Composable
|
||||
fun <T> InfinityPagedComponent(
|
||||
size: Int,
|
||||
|
Reference in New Issue
Block a user