mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-09-06 00:29:57 +00:00
hotfix in InfinityPagedComponent and PagedComponent
This commit is contained in:
@@ -18,7 +18,7 @@ class InfinityPagedComponentContext<T> internal constructor(
|
||||
size: Int
|
||||
) {
|
||||
internal val startPage = SimplePagination(page, size)
|
||||
internal val iterationState: MutableState<Pair<Int, Pagination?>> = mutableStateOf(0 to null)
|
||||
internal val iterationState: MutableState<Pagination?> = mutableStateOf(null)
|
||||
internal val dataState: MutableState<List<T>?> = mutableStateOf(null)
|
||||
internal var lastPageLoaded = false
|
||||
|
||||
@@ -27,11 +27,11 @@ class InfinityPagedComponentContext<T> internal constructor(
|
||||
*/
|
||||
fun loadNext() {
|
||||
if (lastPageLoaded) return
|
||||
if (iterationState.value.second is SimplePagination) return // Data loading has been inited but not loaded yet
|
||||
if (iterationState.value is SimplePagination) return // Data loading has been inited but not loaded yet
|
||||
|
||||
iterationState.value = iterationState.value.let {
|
||||
if ((it.second as? PaginationResult<*>) ?.isLastPage == true) return
|
||||
(it.first + 1) to (it.second ?: startPage).nextPage()
|
||||
if ((it as? PaginationResult<*>) ?.isLastPage == true) return
|
||||
(it ?: startPage).nextPage()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ class InfinityPagedComponentContext<T> internal constructor(
|
||||
dataState.value = null
|
||||
lastPageLoaded = false
|
||||
iterationState.value = iterationState.value.let {
|
||||
(it.first + 1) to null
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,12 +66,12 @@ internal fun <T> InfinityPagedComponent(
|
||||
) {
|
||||
val context = remember { InfinityPagedComponentContext<T>(page, size) }
|
||||
|
||||
LaunchedEffect(context.iterationState.value.first) {
|
||||
val paginationResult = loader(context, context.iterationState.value.second ?: context.startPage)
|
||||
LaunchedEffect(context.iterationState.value ?.page) {
|
||||
val paginationResult = loader(context, context.iterationState.value ?: context.startPage)
|
||||
if (paginationResult.isLastPage) {
|
||||
context.lastPageLoaded = true
|
||||
}
|
||||
context.iterationState.value = context.iterationState.value.copy(second = paginationResult)
|
||||
context.iterationState.value = paginationResult
|
||||
context.dataState.value = (context.dataState.value ?: emptyList()) + paginationResult.results
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user