# LazyLayoutScrollScope

# LazyLayoutScrollScope

Artifact:[androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation)  
[View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/lazy/layout/LazyLayoutScrollScope.kt+class:androidx.compose.foundation.lazy.layout.LazyLayoutScrollScope)  
Added in[1.8.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.8.0)
Common/AllAndroid/JVM
  - Cmn  

  ```
  interface LazyLayoutScrollScope : ScrollScope
  ```

*** ** * ** ***

A[ScrollScope](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollScope)to allow customization of scroll sessions in LazyLayouts. This scope contains additional information to perform a custom scroll session in a scrollable LazyLayout.

For implementations for the most common layouts see:  

|                                                                                                                                       See also                                                                                                                                       |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [LazyLayoutScrollScope](https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/grid/package-summary#LazyLayoutScrollScope(androidx.compose.foundation.lazy.grid.LazyGridState,androidx.compose.foundation.gestures.ScrollScope))                            |   |
| [LazyLayoutScrollScope](https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/staggeredgrid/package-summary#LazyLayoutScrollScope(androidx.compose.foundation.lazy.staggeredgrid.LazyStaggeredGridState,androidx.compose.foundation.gestures.ScrollScope)) |   |
| [LazyLayoutScrollScope](https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/package-summary#LazyLayoutScrollScope(androidx.compose.foundation.lazy.LazyListState,androidx.compose.foundation.gestures.ScrollScope))                                      |   |
| [LazyLayoutScrollScope](https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/package-summary#LazyLayoutScrollScope(androidx.compose.foundation.pager.PagerState,androidx.compose.foundation.gestures.ScrollScope))                                       |   |

## Summary

|                             ### Public functions                              |
|-------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)   | [calculateDistanceTo](https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/LazyLayoutScrollScope#calculateDistanceTo(kotlin.Int,kotlin.Int))`(targetIndex: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, targetOffset: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` The "expected" distance to[targetIndex](https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/LazyLayoutScrollScope#calculateDistanceTo(kotlin.Int,kotlin.Int)).                                                                                                                    | Cmn |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [snapToItem](https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/LazyLayoutScrollScope#snapToItem(kotlin.Int,kotlin.Int))`(index: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, offset: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Immediately scroll to[index](https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/LazyLayoutScrollScope#snapToItem(kotlin.Int,kotlin.Int))and settle in[offset](https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/LazyLayoutScrollScope#snapToItem(kotlin.Int,kotlin.Int)). | Cmn |

|                            ### Public properties                            |
|-----------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [firstVisibleItemIndex](https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/LazyLayoutScrollScope#firstVisibleItemIndex()) The index of the first visible item in the lazy layout.                                                                  | Cmn |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [firstVisibleItemScrollOffset](https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/LazyLayoutScrollScope#firstVisibleItemScrollOffset()) The offset of the first visible item.                                                                      | Cmn |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [itemCount](https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/LazyLayoutScrollScope#itemCount()) The total item count.                                                                                                                            | Cmn |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [lastVisibleItemIndex](https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/LazyLayoutScrollScope#lastVisibleItemIndex()) The last visible item in the LazyLayout, lastVisibleItemIndex - firstVisibleItemOffset + 1 is the number of visible items. | Cmn |

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              ### Inherited functions                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| From[androidx.compose.foundation.gestures.ScrollScope](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollScope) |---------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----| | [Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | [scrollBy](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollScope#scrollBy(kotlin.Float))`(pixels: `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)`)` Attempts to scroll forward by[pixels](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollScope#scrollBy(kotlin.Float))px. | Cmn | |

## Public functions

### calculateDistanceTo

Cmn  
Added in[1.8.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.8.0)  

```
fun calculateDistanceTo(targetIndex: Int, targetOffset: Int = 0): Int
```

The "expected" distance to[targetIndex](https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/LazyLayoutScrollScope#calculateDistanceTo(kotlin.Int,kotlin.Int)). This means the "expected" offset of[targetIndex](https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/LazyLayoutScrollScope#calculateDistanceTo(kotlin.Int,kotlin.Int))in the layout. In a LazyLayout, non-visible items don't have an actual offset, so this method should return an approximation of the scroll offset to[targetIndex](https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/LazyLayoutScrollScope#calculateDistanceTo(kotlin.Int,kotlin.Int)). If[targetIndex](https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/LazyLayoutScrollScope#calculateDistanceTo(kotlin.Int,kotlin.Int))is visible, then an "exact" offset should be provided.  

|                                            Parameters                                             |
|---------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------|
| `targetIndex: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)        | The index position with respect to which this calculation should be done. |
| `targetOffset: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` = 0` | The offset with respect to which this calculation should be done.         |

|                                   Returns                                   |
|-----------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The expected distance to scroll so[targetIndex](https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/LazyLayoutScrollScope#calculateDistanceTo(kotlin.Int,kotlin.Int))is the firstVisibleItemIndex with[targetOffset](https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/LazyLayoutScrollScope#calculateDistanceTo(kotlin.Int,kotlin.Int))as the firstVisibleItemScrollOffset. |

### snapToItem

Cmn  
Added in[1.8.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.8.0)  

```
fun snapToItem(index: Int, offset: Int = 0): Unit
```

Immediately scroll to[index](https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/LazyLayoutScrollScope#snapToItem(kotlin.Int,kotlin.Int))and settle in[offset](https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/LazyLayoutScrollScope#snapToItem(kotlin.Int,kotlin.Int)).  

|                                         Parameters                                          |
|---------------------------------------------------------------------------------------------|---------------------------------------------------------|
| `index: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)        | The position index where we should immediately snap to. |
| `offset: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` = 0` | The offset where we should immediately snap to.         |

## Public properties

### firstVisibleItemIndex

Cmn  
Added in[1.8.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.8.0)  

```
val firstVisibleItemIndex: Int
```

The index of the first visible item in the lazy layout.  

### firstVisibleItemScrollOffset

Cmn  
Added in[1.8.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.8.0)  

```
val firstVisibleItemScrollOffset: Int
```

The offset of the first visible item.  

### itemCount

Cmn  
Added in[1.8.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.8.0)  

```
val itemCount: Int
```

The total item count.  

### lastVisibleItemIndex

Cmn  
Added in[1.8.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.8.0)  

```
val lastVisibleItemIndex: Int
```

The last visible item in the LazyLayout, lastVisibleItemIndex - firstVisibleItemOffset + 1 is the number of visible items.