# SlidingWindowEffect

## Functions summary

|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/media3/common/util/UnstableApi @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/lifecycle/SlidingWindowEffect.composable#SlidingWindowEffect(kotlin.Function0,kotlin.Function0,kotlin.Int,kotlin.Int,kotlin.Int,kotlin.Int,kotlin.Function1,kotlin.Function1)( itemCountProvider: () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, currentItemProvider: () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, maxLookbehind: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, maxLookahead: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, batchSize: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, prefetchDistance: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, onRangeEnterWindow: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.ranges/-int-range/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html, onRangeLeaveWindow: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.ranges/-int-range/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` A side effect that calculates a sliding window of managed item indices based on a dynamic current index. |

## Functions

### SlidingWindowEffect

Artifact: [androidx.media3:media3-ui-compose](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/ui/compose/lifecycle/SlidingWindowEffect.kt+function: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 `https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/lifecycle/package-summary#SlidingWindowEffect(kotlin.Function0,kotlin.Function0,kotlin.Int,kotlin.Int,kotlin.Int,kotlin.Int,kotlin.Function1,kotlin.Function1)` when items should be prepared/loaded, and `https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/lifecycle/package-summary#SlidingWindowEffect(kotlin.Function0,kotlin.Function0,kotlin.Int,kotlin.Int,kotlin.Int,kotlin.Int,kotlin.Function1,kotlin.Function1)` when they fall outside the managed window boundaries and should be evicted.

The effect guarantees that all indices passed to `https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/lifecycle/package-summary#SlidingWindowEffect(kotlin.Function0,kotlin.Function0,kotlin.Int,kotlin.Int,kotlin.Int,kotlin.Int,kotlin.Function1,kotlin.Function1)` and `https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/lifecycle/package-summary#SlidingWindowEffect(kotlin.Function0,kotlin.Function0,kotlin.Int,kotlin.Int,kotlin.Int,kotlin.Int,kotlin.Function1,kotlin.Function1)` will always be within the valid range of `0 until itemCountProvider()`.

| Parameters |
|---|---|
| `itemCountProvider: () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | A lambda returning the total number of items available to scroll through. |
| `currentItemProvider: () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | A lambda returning the currently focused item index. |
| `maxLookbehind: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The maximum number of items to keep actively managed in memory before the current item. |
| `maxLookahead: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The maximum number of items to keep actively managed in memory after the current item. |
| `batchSize: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The number of items to load/evict at once when crossing the prefetchDistance threshold. |
| `prefetchDistance: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = 2` | The distance from the edge of the window that triggers the next batch of preloads. |
| `onRangeEnterWindow: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.ranges/-int-range/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | Callback invoked with the contiguous range of indices that have entered the window. These indices are guaranteed to be within `0 until itemCountProvider()`. |
| `onRangeLeaveWindow: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.ranges/-int-range/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | 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 `https://developer.android.com/reference/kotlin/androidx/media3/ui/compose/lifecycle/package-summary#SlidingWindowEffect(kotlin.Function0,kotlin.Function0,kotlin.Int,kotlin.Int,kotlin.Int,kotlin.Int,kotlin.Function1,kotlin.Function1)`. |