LazyLayoutAnimateScrollScope


A scope to allow customization of animated scroll in LazyLayouts. This scope contains all needed information to perform an animatedScroll in a scrollable LazyLayout.

For implementations for the most common layouts see:

Summary

Public functions

Int
calculateDistanceTo(targetIndex: Int, targetOffset: Int)

The "expected" distance to targetIndex.

Cmn
Unit
ScrollScope.snapToItem(index: Int, offset: Int)

Immediately scroll to index and settle in offset.

Cmn

Public properties

Int

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

Cmn
Int

The offset of the first visible item.

Cmn
Int

The total item count.

Cmn
Int

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

Cmn

Public functions

calculateDistanceTo

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

The "expected" distance to targetIndex. This means the "expected" offset of targetIndex 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. If targetIndex is visible, then an "exact" offset should be provided.

Parameters
targetIndex: Int

The index position with respect to which this calculation should be done.

targetOffset: Int = 0

The offset with respect to which this calculation should be done.

Returns
Int

The expected distance to scroll so targetIndex is the firstVisibleItemIndex with targetOffset as the firstVisibleItemScrollOffset.

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

Immediately scroll to index and settle in offset.

Parameters
index: Int

The position index where we should immediately snap to.

offset: Int = 0

The offset where we should immediately snap to.

Public properties

firstVisibleItemIndex

val firstVisibleItemIndexInt

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

firstVisibleItemScrollOffset

val firstVisibleItemScrollOffsetInt

The offset of the first visible item.

itemCount

val itemCountInt

The total item count.

lastVisibleItemIndex

val lastVisibleItemIndexInt

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