🌈 Create new beautiful Compose Gradients with our new wesite ->
Class

LazyStaggeredGridState

Hoisted state object controlling LazyVerticalStaggeredGrid or LazyHorizontalStaggeredGrid.

Source set: Common
public class LazyStaggeredGridState internal constructor(
    initialFirstVisibleItems: IntArray,
    initialFirstVisibleOffsets: IntArray,
    // Only used for testing purposes.
    prefetchScheduler: PrefetchScheduler?,
) : ScrollableState

Hoisted state object controlling LazyVerticalStaggeredGrid or LazyHorizontalStaggeredGrid. In most cases, it should be created via rememberLazyStaggeredGridState.

Properties

firstVisibleItemIndex

Source set: Common
public val firstVisibleItemIndex: Int

Index of the first visible item across all staggered grid lanes. This does not include items in the content padding region. For the first visible item that includes items in the content padding please use LazyStaggeredGridLayoutInfo.visibleItemsInfo.

This property is observable and when use it in composable function it will be recomposed on each scroll, potentially causing performance issues.

firstVisibleItemScrollOffset

Source set: Common
public val firstVisibleItemScrollOffset: Int

Current offset of the item with firstVisibleItemIndex relative to the container start.

This property is observable and when use it in composable function it will be recomposed on each scroll, potentially causing performance issues.

layoutInfo

Source set: Common
public val layoutInfo: LazyStaggeredGridLayoutInfo

Layout information calculated during last layout pass, with information about currently visible items and container parameters.

This property is observable and when use it in composable function it will be recomposed on each scroll, potentially causing performance issues.

canScrollForward

Source set: Common
override var canScrollForward: Boolean by mutableStateOf(false)

canScrollBackward

Source set: Common
override var canScrollBackward: Boolean by mutableStateOf(false)

lastScrolledForward

Source set: Common
override val lastScrolledForward: Boolean

lastScrolledBackward

Source set: Common
override val lastScrolledBackward: Boolean

scrollIndicatorState

Source set: Common
override val scrollIndicatorState: ScrollIndicatorState?

interactionSource

Source set: Common
public val interactionSource: InteractionSource

InteractionSource that will be used to dispatch drag events when this list is being dragged. If you want to know whether the fling (or animated scroll) is in progress, use isScrollInProgress.

isScrollInProgress

Source set: Common
override val isScrollInProgress: Boolean

Whether this scrollableState is currently scrolling by gesture, fling or programmatically or not.

Functions

scroll

Source set: Common
override suspend fun scroll(
        scrollPriority: MutatePriority,
        block: suspend ScrollScope.() -> Unit,
    )

Call this function to take control of scrolling and gain the ability to send scroll events via ScrollScope.scrollBy. All actions that change the logical scroll position must be performed within a scroll block (even if they don't call any other methods on this object) in order to guarantee that mutual exclusion is enforced.

If scroll is called from elsewhere, this will be canceled.

scrollToItem

Source set: Common
public suspend fun scrollToItem(
        /* @IntRange(from = 0) */
        index: Int,
        scrollOffset: Int = 0,
    )

Instantly brings the item at index to the top of layout viewport, offset by scrollOffset pixels.

Parameters

index the index to which to scroll. MUST NOT be negative.
scrollOffset the offset where the item should end up after the scroll. Note that positive offset refers to forward scroll, so in a reversed list, positive offset will scroll the item further upward (taking it partly offscreen).

animateScrollToItem

Source set: Common
public suspend fun animateScrollToItem(
        /* @IntRange(from = 0) */
        index: Int,
        scrollOffset: Int = 0,
    )

Animate (smooth scroll) to the given item.

Parameters

index the index to which to scroll. MUST NOT be negative.
scrollOffset the offset that the item should end up after the scroll. Note that positive offset refers to forward scroll, so in a top-to-bottom list, positive offset will scroll the item further upward (taking it partly offscreen).

requestScrollToItem

Source set: Common
public fun requestScrollToItem(@AndroidXIntRange(from = 0) index: Int, scrollOffset: Int = 0)

Requests the item at index to be at the start of the viewport during the next remeasure, offset by scrollOffset, and schedules a remeasure.

The scroll position will be updated to the requested position rather than maintain the index based on the first visible 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

index the index to which to scroll. Must be non-negative.
scrollOffset the offset that the item should end up after the scroll. Note that positive offset refers to forward scroll, so in a top-to-bottom list, positive offset will scroll the item further upward (taking it partly offscreen).

dispatchRawDelta

Source set: Common
override fun dispatchRawDelta(delta: Float): Float

Members

Companion

Source set: Common
public companion object

Properties

Saver

Source set: Common
public val Saver: Saver<LazyStaggeredGridState, Any> =
            listSaver(
                save = { state ->
                    listOf(state.scrollPosition.indices, state.scrollPosition.scrollOffsets)
                },
                restore = { LazyStaggeredGridState(it[0], it[1], null) },
            )

The default implementation of Saver for LazyStaggeredGridState