SlidingWindowEffect

Functions summary

Unit
@UnstableApi
@Composable
SlidingWindowEffect(
    itemCountProvider: () -> Int,
    currentItemProvider: () -> Int,
    maxLookbehind: Int,
    maxLookahead: Int,
    batchSize: Int,
    prefetchDistance: Int,
    onRangeEnterWindow: (IntRange) -> Unit,
    onRangeLeaveWindow: (IntRange) -> Unit
)

A side effect that calculates a sliding window of managed item indices based on a dynamic current index.

Functions

SlidingWindowEffect

@UnstableApi
@Composable
fun SlidingWindowEffect(
    itemCountProvider: () -> Int,
    currentItemProvider: () -> Int,
    maxLookbehind: Int,
    maxLookahead: Int,
    batchSize: Int,
    prefetchDistance: Int = 2,
    onRangeEnterWindow: (IntRange) -> Unit,
    onRangeLeaveWindow: (IntRange) -> Unit
): Unit

A side effect that calculates a sliding window of managed item indices based on a dynamic current index.

It invokes onRangeEnterWindow when items should be prepared/loaded, and onRangeLeaveWindow when they fall outside the managed window boundaries and should be evicted.

The effect guarantees that all indices passed to onRangeEnterWindow and onRangeLeaveWindow will always be within the valid range of 0 until itemCountProvider().

Parameters
itemCountProvider: () -> Int

A lambda returning the total number of items available to scroll through.

currentItemProvider: () -> Int

A lambda returning the currently focused item index.

maxLookbehind: Int

The maximum number of items to keep actively managed in memory before the current item.

maxLookahead: Int

The maximum number of items to keep actively managed in memory after the current item.

batchSize: Int

The number of items to load/evict at once when crossing the prefetchDistance threshold.

prefetchDistance: Int = 2

The distance from the edge of the window that triggers the next batch of preloads.

onRangeEnterWindow: (IntRange) -> Unit

Callback invoked with the contiguous range of indices that have entered the window. These indices are guaranteed to be within 0 until itemCountProvider().

onRangeLeaveWindow: (IntRange) -> Unit

Callback invoked with the contiguous range of indices that have left the window. This is also called to evict indices that have become invalid/out-of-bounds due to a decrease in itemCountProvider.