The Developer Preview for Android 11 is now available; test it out and share your feedback.

ScrollerPosition

@Model class ScrollerPosition
kotlin.Any
   ↳ androidx.ui.foundation.ScrollerPosition

This is the state of a VerticalScroller and HorizontalScroller that allows the developer to change the scroll position by calling methods on this object.

Summary

Public constructors

<init>(flingConfig: FlingConfig, initial: Float = 0f)

This is the state of a VerticalScroller and HorizontalScroller that allows the developer to change the scroll position by calling methods on this object.

Public methods

Unit
fling(startVelocity: Float)

Starts a fling animation with the specified starting velocity and the previously set flingConfig

Unit
scrollBy(value: Px)

Instantly jump by some amount of pixels

Unit
scrollTo(value: Px)

Instantly jump to position in pixels

Unit
smoothScrollBy(value: Px, onEnd: (endReason: AnimationEndReason, finishValue: Float) -> Unit = { _, _ -> })

Smooth scroll by some amount of pixels

Unit
smoothScrollTo(value: Px, onEnd: (endReason: AnimationEndReason, finishValue: Float) -> Unit = { _, _ -> })

Smooth scroll to position in pixels

Inherited extension functions

From androidx.compose
operator T

IMPORTANT: This global operator is TEMPORARY, and should be removed whenever an answer for contextual composers is reached.

Properties

FlingConfig

Configuration that specifies fling logic when scrolling ends with velocity.

Boolean

whether this ScrollerPosition is currently animating

Px

maxPosition this scroller that consume this ScrollerPosition can reach, or Px.Infinity if still unknown

Px

current position for scroller

Public constructors

<init>

ScrollerPosition(
    flingConfig: FlingConfig,
    initial: Float = 0f)

This is the state of a VerticalScroller and HorizontalScroller that allows the developer to change the scroll position by calling methods on this object.

Public methods

fling

fun fling(startVelocity: Float): Unit

Starts a fling animation with the specified starting velocity and the previously set flingConfig

Parameters
startVelocity: Float Starting velocity of the fling animation

scrollBy

fun scrollBy(value: Px): Unit

Instantly jump by some amount of pixels

Parameters
value: Px delta to jump by

scrollTo

fun scrollTo(value: Px): Unit

Instantly jump to position in pixels

Parameters
value: Px target value to jump to

smoothScrollBy

fun smoothScrollBy(
    value: Px,
    onEnd: (endReason: AnimationEndReason, finishValue: Float) -> Unit = { _, _ -> }
): Unit

Smooth scroll by some amount of pixels

Parameters
value: Px delta to scroll by

smoothScrollTo

fun smoothScrollTo(
    value: Px,
    onEnd: (endReason: AnimationEndReason, finishValue: Float) -> Unit = { _, _ -> }
): Unit

Smooth scroll to position in pixels

Parameters
value: Px target value to smooth scroll to

Properties

flingConfig

val flingConfig: FlingConfig

Configuration that specifies fling logic when scrolling ends with velocity.

isAnimating

var isAnimating: Boolean

whether this ScrollerPosition is currently animating

maxPosition

var maxPosition: Px

maxPosition this scroller that consume this ScrollerPosition can reach, or Px.Infinity if still unknown

value

val value: Px

current position for scroller