ThresholdReachedEffect

fun Int.ThresholdReachedEffect(lazyListState: LazyListState, considerLoadingItemAtEnd: Boolean = true, onThresholdReached: () -> Unit)

Fires onThresholdReached when the last visible item of lazyListState comes within this many items of the end of the list — the infinite-scroll pagination guard behind LazyColumn/LazyRow's scrollThreshold and their OnScrollThresholdReached trigger. Public and reusable outside the built-in lazy tiles for a custom lazy-list-style tile that wants the same pagination behavior.

The guard against re-firing on every recomposition while sitting past the threshold: it tracks the item count at the last time it fired (considerLoadingItemAtEnd adds 1 to that baseline, to account for a trailing loading placeholder item), and only fires again once lazyListState.layoutInfo.totalItemsCount has actually grown past that baseline — so appending items without also growing the list past the placeholder doesn't cause a second fire, and a list that never grows only fires once total.

That baseline is also lowered whenever totalItemsCount dips below its previous peak — the signature of a failed page load whose loading placeholder got swapped for an error tile with no net growth (RemoveTiles then AddTiles, same count). Without this, a failure permanently blocks re-pagination even after the list would otherwise grow past the stale baseline again.

Receiver

the threshold: how many items from the end of the list counts as "reached".

Parameters

lazyListState

the list's own scroll state to observe.

considerLoadingItemAtEnd

when true (the default), requires the list to have grown by more than one item since the last fire before firing again — accounting for a trailing loading placeholder that would otherwise count as "growth" on its own.

onThresholdReached

called (from a LaunchedEffect) when the threshold is newly reached.