public class ScrollState(initial: Int) : ScrollableState
State of the scroll. Allows the developer to change the scroll position or get current state by calling methods on this object. To be hosted and passed to Modifier.verticalScroll or Modifier.horizontalScroll
To create and automatically remember ScrollState with default parameters use rememberScrollState.
Learn how to control the state of Modifier.verticalScroll or Modifier.horizontalScroll:
Parameters
| initial | value of the scroll |
Properties
value
public var value: Int by mutableIntStateOf(initial)
current scroll position value in pixels
maxValue
public var maxValue: Int
maximum bound for value, or Int.MAX_VALUE if still unknown
viewportSize
public var viewportSize: Int by mutableIntStateOf(0)
Size of the viewport on the scrollable axis, or 0 if still unknown. Note that this value is only populated after the first measure pass.
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 smooth scroll) is in progress, use isScrollInProgress.
isScrollInProgress
override val isScrollInProgress: Boolean
canScrollForward
override val canScrollForward: Boolean { value < maxValue }
override val canScrollBackward: Boolean {
lastScrolledBackward
override val lastScrolledBackward: Boolean
scrollIndicatorState
override val scrollIndicatorState: ScrollIndicatorState?
Functions
scroll
override suspend fun scroll(
scrollPriority: MutatePriority,
block: suspend ScrollScope.() -> Unit,
): Unit
dispatchRawDelta
override fun dispatchRawDelta(delta: Float): Float
animateScrollTo
public suspend fun animateScrollTo(
value: Int,
animationSpec: AnimationSpec<Float> = SpringSpec(),
)
Scroll to position in pixels with animation.
Parameters
| value | target value in pixels to smooth scroll to, value will be coerced to 0..maxPosition |
| animationSpec | animation curve for smooth scroll animation |
scrollTo
public suspend fun scrollTo(value: Int): Float
Instantly jump to the given position in pixels.
Cancels the currently running scroll, if any, and suspends until the cancellation is complete.
Parameters
| value | number of pixels to scroll by |
Return
the amount of scroll consumed
Members
Companion
public companion object
Properties
Saver
public val Saver: Saver<ScrollState, *> =
Saver(save = { it.value }, restore = { ScrollState(it) })
The default Saver implementation for ScrollState.