TvLazyListState

class TvLazyListState : ScrollableState


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

In most cases, this will be created via rememberTvLazyListState.

Summary

Public companion properties

Saver<TvLazyListState, *>

The default Saver implementation for TvLazyListState.

Public constructors

TvLazyListState(
    firstVisibleItemIndex: Int,
    firstVisibleItemScrollOffset: Int
)

Public functions

suspend Unit
animateScrollToItem(index: Int, scrollOffset: Int)

Animate (smooth scroll) to the given item.

open Float
open suspend Unit
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.

suspend Unit
scrollToItem(index: Int, scrollOffset: Int)

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

Public properties

open Boolean
open Boolean
Int

The index of the first item that is visible.

Int

The scroll offset of the first visible item.

InteractionSource

InteractionSource that will be used to dispatch drag events when this list is being dragged.

open Boolean
TvLazyListLayoutInfo

The object of TvLazyListLayoutInfo calculated during the last layout pass.

Public companion properties

Saver

Added in 1.0.0-alpha11
Deprecated in 1.0.0-alpha11
val SaverSaver<TvLazyListState, *>

The default Saver implementation for TvLazyListState.

Public constructors

TvLazyListState

Added in 1.0.0-alpha11
Deprecated in 1.0.0-alpha11
TvLazyListState(
    firstVisibleItemIndex: Int = 0,
    firstVisibleItemScrollOffset: Int = 0
)
Parameters
firstVisibleItemIndex: Int = 0

the initial value for TvLazyListState.firstVisibleItemIndex

firstVisibleItemScrollOffset: Int = 0

the initial value for TvLazyListState.firstVisibleItemScrollOffset

Public functions

animateScrollToItem

Added in 1.0.0-alpha11
Deprecated in 1.0.0-alpha11
suspend fun animateScrollToItem(index: Int, scrollOffset: Int = 0): Unit

Animate (smooth scroll) to the given item.

Parameters
index: Int

the index to which to scroll. Must be non-negative.

scrollOffset: Int = 0

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

Added in 1.0.0-alpha11
Deprecated in 1.0.0-alpha11
open fun dispatchRawDelta(delta: Float): Float

scroll

Added in 1.0.0-alpha11
Deprecated in 1.0.0-alpha11
open suspend fun scroll(scrollPriority: MutatePriority, block: suspend ScrollScope.() -> Unit): 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

Added in 1.0.0-alpha11
Deprecated in 1.0.0-alpha11
suspend fun scrollToItem(index: Int, scrollOffset: Int = 0): Unit

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

Parameters
index: Int

the index to which to scroll. Must be non-negative.

scrollOffset: Int = 0

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).

Public properties

canScrollBackward

open val canScrollBackwardBoolean

canScrollForward

open val canScrollForwardBoolean

firstVisibleItemIndex

Added in 1.0.0-alpha11
Deprecated in 1.0.0-alpha11
val firstVisibleItemIndexInt

The index of the first item that is visible.

Note that this property is observable and if you use it in the composable function it will be recomposed on every change causing potential performance issues.

If you want to run some side effects like sending an analytics event or updating a state based on this value consider using "snapshotFlow".

If you need to use it in the composition then consider wrapping the calculation into a derived state in order to only have recompositions when the derived value changes.

firstVisibleItemScrollOffset

Added in 1.0.0-alpha11
Deprecated in 1.0.0-alpha11
val firstVisibleItemScrollOffsetInt

The scroll offset of the first visible item. Scrolling forward is positive - i.e., the amount that the item is offset backwards.

Note that this property is observable and if you use it in the composable function it will be recomposed on every scroll causing potential performance issues.

See also
firstVisibleItemIndex

for samples with the recommended usage patterns.

interactionSource

Added in 1.0.0-alpha11
Deprecated in 1.0.0-alpha11
val interactionSourceInteractionSource

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

Added in 1.0.0-alpha11
Deprecated in 1.0.0-alpha11
open val isScrollInProgressBoolean

layoutInfo

Added in 1.0.0-alpha11
Deprecated in 1.0.0-alpha11
val layoutInfoTvLazyListLayoutInfo

The object of TvLazyListLayoutInfo calculated during the last layout pass. For example, you can use it to calculate what items are currently visible.

Note that this property is observable and is updated after every scroll or remeasure. If you use it in the composable function it will be recomposed on every change causing potential performance issues including infinity recomposition loop. Therefore, avoid using it in the composition.

If you want to run some side effects like sending an analytics event or updating a state based on this value consider using "snapshotFlow"