SlidingWindowEffect

Functions summary

Unit
@UnstableApi
@Composable
SlidingWindowEffect(
    itemCount: 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 items based on a dynamic current index.

Functions

SlidingWindowEffect

@UnstableApi
@Composable
fun SlidingWindowEffect(
    itemCount: 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 items 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.

Parameters
itemCount: Int

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.

onRangeLeaveWindow: (IntRange) -> Unit

Callback invoked with the contiguous range of indices that have left the window.