Updated on 2026-08-14
This commit is contained in:
parent
a40134890d
commit
05ce66184b
3 changed files with 7 additions and 13 deletions
|
|
@ -6,18 +6,15 @@ import androidx.compose.runtime.*
|
|||
@Composable
|
||||
fun LazyListState.OnBottomReached(loadMoreThreshold: Int, loadMore: () -> Unit) {
|
||||
require(loadMoreThreshold >= 0)
|
||||
val shouldLoadMore = remember {
|
||||
val shouldLoadMore by remember {
|
||||
derivedStateOf {
|
||||
val lastVisibleItem = layoutInfo.visibleItemsInfo.lastOrNull()
|
||||
?: return@derivedStateOf false
|
||||
lastVisibleItem.index >= layoutInfo.totalItemsCount - 1 - loadMoreThreshold
|
||||
lastVisibleItem.index >= layoutInfo.totalItemsCount - 1 - loadMoreThreshold
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(shouldLoadMore) {
|
||||
snapshotFlow { shouldLoadMore.value }
|
||||
.collect { shouldLoadMore ->
|
||||
if (shouldLoadMore) loadMore()
|
||||
}
|
||||
if (shouldLoadMore) loadMore()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue