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

ScrollableState

class ScrollableState
kotlin.Any
   ↳ androidx.ui.foundation.gestures.ScrollableState

State of the scrollable composable. Contains necessary information about ongoing fling and provides smooth scrolling capabilities.

Summary

Public constructors

<init>(onScrollDeltaConsumptionRequested: (Float) -> Float, flingConfig: FlingConfig, animationClock: AnimationClockObservable)

State of the scrollable composable.

Public methods

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

Smooth scroll by value amount of pixels

Unit

Stop any animation, smooth scrolling or fling ongoing for this scrollable

Properties

FlingConfig

configuration that specifies fling logic when scrolling ends with velocity

Boolean

whether this ScrollableState is currently animating/flinging

(Float) -> Float

callback to be invoked when scrollable drag/fling/smooth scrolling occurs.

Public constructors

<init>

ScrollableState(
    onScrollDeltaConsumptionRequested: (Float) -> Float,
    flingConfig: FlingConfig,
    animationClock: AnimationClockObservable)

State of the scrollable composable. Contains necessary information about ongoing fling and provides smooth scrolling capabilities.

Parameters
onScrollDeltaConsumptionRequested: (Float) -> Float callback to be invoked when scrollable drag/fling/smooth scrolling occurs. Users must update their state in this lambda and return amount of delta consumed
flingConfig: FlingConfig configuration that specifies fling logic when scrolling ends with velocity
animationClock: AnimationClockObservable clock observable to run animation on. Consider querying AnimationClockAmbient to get current composition value

Public methods

smoothScrollBy

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

Smooth scroll by value amount of pixels

Parameters
value: Float delta to scroll by
onEnd: (endReason: AnimationEndReason, finishValue: Float) -> Unit = { _, _ -> } lambda to be called when smooth scrolling has ended

stopAnimation

fun stopAnimation(): Unit

Stop any animation, smooth scrolling or fling ongoing for this scrollable

Call this to stop receiving scrollable deltas in onScrollDeltaConsumptionRequested

Properties

flingConfig

val flingConfig: FlingConfig

configuration that specifies fling logic when scrolling ends with velocity

isAnimating

val isAnimating: Boolean

whether this ScrollableState is currently animating/flinging

onScrollDeltaConsumptionRequested

val onScrollDeltaConsumptionRequested: (Float) -> Float

callback to be invoked when scrollable drag/fling/smooth scrolling occurs. Users must update their state in this lambda and return amount of delta consumed