Ali Albaali
12/13/2021, 10:17 PM@NonRestartableComposable
@Composable
inline fun <T> PagingEffect(
iterable: Iterable<T>,
currentIndex: Int,
crossinline block: (T) -> Unit,
) {
SideEffect {
iterable.runOnIndex(currentIndex, block)
}
}
inline fun <T> Iterable<T>.runOnIndex(currentIndex: Int, block: (T) -> Unit) {
withIndex().last().apply {
if (index == currentIndex)
block(value)
}
}
And using it like this:
LazyColumn {
val list = listOf<Item>()
itemsIndexed(list) { index, item ->
PagingEffect(list, index) {
// Request more items
}
}
}
Is there a better way?