2023/10/23
Topics
Compose
- ページネーションしたいけど Paging ライブラリは notifyItemChanged がないのでちょっとなぁ...
@Composable
fun LazyGridState.onBottomReached(buffer: Int = 5, onBottomReached: () -> Unit) = apply {
val shouldLoadMoreBuffer = remember(layoutInfo.visibleItemsInfo) {
val lastVisibleItem = layoutInfo.visibleItemsInfo.lastOrNull() ?: return@remember false
lastVisibleItem.index >= layoutInfo.totalItemsCount - buffer
}
LaunchedEffect(shouldLoadMoreBuffer) {
snapshotFlow { shouldLoadMoreBuffer }
.filter { it }
.collect { onBottomReached() }
}}