TransformingLazyColumnState

Class

Android
public class TransformingLazyColumnState
internal constructor(
    initialAnchorItemIndex: Int,
    initialAnchorItemScrollOffset: Int,
    private val prefetchStrategy: TransformingLazyColumnPrefetchStrategy =
        DefaultTransformingLazyColumnPrefetchStrategy(),
) : ScrollableState

A state object that can be hoisted to control and observe scrolling.

In most cases, this will be created via rememberTransformingLazyColumnState.

Secondary Constructors

public constructor(
    initialAnchorItemIndex: Int = 0,
    initialAnchorItemScrollOffset: Int = 0,
) : this(
    initialAnchorItemIndex = initialAnchorItemIndex,
    initialAnchorItemScrollOffset = initialAnchorItemScrollOffset,
    prefetchStrategy = DefaultTransformingLazyColumnPrefetchStrategy(),
)

Parameters

initialAnchorItemIndexthe index of an item that is going to be placed in the center of the screen (if possible). This correlates with TransformingLazyColumnState.anchorItemIndex.
initialAnchorItemScrollOffsetthe offset of an item to be used when placing the item in the center of the screen (if possible). This correlates with TransformingLazyColumnState.anchorItemScrollOffset.
public constructor() :
    this(
        initialAnchorItemIndex = 0,
        initialAnchorItemScrollOffset = 0,
        prefetchStrategy = DefaultTransformingLazyColumnPrefetchStrategy(),
    )

Functions

public suspend fun scrollToItem(
        @androidx.annotation.IntRange(from = 0) index: Int,
        scrollOffset: Int = 0,
    )

Scrolls the item specified by index to the center of the screen.

The scroll position anchorItemIndex and anchorItemScrollOffset will be updated to take into account the new layout. There is no guarantee that index will become the new anchorItemIndex since requested scrollOffset may position item with another index closer to the anchor point.

This operation happens instantly without animation.

Parameters

indexThe index of the item to scroll to. Must be non-negative.
scrollOffsetThe offset between the center of the screen and item's center. Positive offset means the item will be scrolled up.
public fun requestScrollToItem(
        @androidx.annotation.IntRange(from = 0) index: Int,
        scrollOffset: Int = 0,
    )

Requests the item at index to be at the center of the viewport during the next remeasure, offset by scrollOffset.

The scroll position anchorItemIndex and anchorItemScrollOffset will be updated to take into account the new layout. There is no guarantee that index will become the new anchorItemIndex since requested scrollOffset may position item with another index closer to the anchor point.

The scroll position will be updated to the requested position rather than maintain the index based on the center item key (when a data set change will also be applied during the next remeasure), but only for the next remeasure.

Any scroll in progress will be cancelled.

Parameters

indexthe index to which to scroll. Must be non-negative.
scrollOffsetThe offset between the center of the screen and item's center. Positive offset means the item will be scrolled up.
public suspend fun animateScrollToItem(
        @androidx.annotation.IntRange(from = 0) index: Int,
        scrollOffset: Int = 0,
    )

Animate (smooth scroll) to the given item.

The scroll position anchorItemIndex and anchorItemScrollOffset will be updated to take into account the new layout. There is no guarantee that index will become the new anchorItemIndex since requested scrollOffset may position item with another index closer to the anchor point.

Parameters

indexthe index to which to scroll. Must be non-negative.
scrollOffsetThe offset between the center of the screen and item's center. Positive offset means the item will be scrolled up.

Companion Object