LazyStaggeredGridState
class LazyStaggeredGridState
internal constructor(
initialFirstVisibleItems: IntArray,
initialFirstVisibleOffsets: IntArray,
prefetchScheduler: PrefetchScheduler?,
) : ScrollableState
Hoisted state object controlling LazyVerticalStaggeredGrid
or LazyHorizontalStaggeredGrid
. In
most cases, it should be created via rememberLazyStaggeredGridState
.
Secondary Constructors
constructor(
initialFirstVisibleItemIndex: Int = 0,
initialFirstVisibleItemOffset: Int = 0,
) : this(
intArrayOf(initialFirstVisibleItemIndex),
intArrayOf(initialFirstVisibleItemOffset),
null,
)
Parameters
initialFirstVisibleItemIndex | initial value for firstVisibleItemIndex |
initialFirstVisibleItemOffset | initial value for firstVisibleItemScrollOffset |
Properties
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.
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.
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.
val 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
.
Functions
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). |
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). |
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). |
Companion Object
Properties
val Saver =
listSaver<LazyStaggeredGridState, IntArray>(
save = { state ->
listOf(state.scrollPosition.indices, state.scrollPosition.scrollOffsets)
},
restore = { LazyStaggeredGridState(it[0], it[1], null) },
)
The default implementation of Saver
for LazyStaggeredGridState