Updated on 2026-08-14

This commit is contained in:
Tangem 2022-05-30 17:35:48 +04:00
parent 8176ce8032
commit 3d72284f67
4 changed files with 45 additions and 23 deletions

View file

@ -0,0 +1,23 @@
package com.tangem.tap.common.compose.extensions
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.runtime.*
@Composable
fun LazyListState.OnBottomReached(loadMoreThreshold: Int, loadMore: () -> Unit) {
require(loadMoreThreshold >= 0)
val shouldLoadMore = remember {
derivedStateOf {
val lastVisibleItem = layoutInfo.visibleItemsInfo.lastOrNull()
?: return@derivedStateOf false
lastVisibleItem.index >= layoutInfo.totalItemsCount - 1 - loadMoreThreshold
}
}
LaunchedEffect(shouldLoadMore) {
snapshotFlow { shouldLoadMore.value }
.collect { shouldLoadMore ->
if (shouldLoadMore) loadMore()
}
}
}