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
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
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
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
override var canScrollForward: Boolean by mutableStateOf(false)
canScrollBackward
override var canScrollBackward: Boolean by mutableStateOf(false)
lastScrolledForward
override val lastScrolledForward: Boolean
lastScrolledBackward
override val lastScrolledBackward: Boolean
scrollIndicatorState
override val scrollIndicatorState: ScrollIndicatorState?
interactionSource
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
override val isScrollInProgress: Boolean
Whether this scrollableState is currently scrolling by gesture, fling or programmatically or not.
Functions
scroll
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
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
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
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
override fun dispatchRawDelta(delta: Float): Float
Members
Companion
public companion object
Properties
Saver
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