Google is committed to advancing racial equity for Black communities. See how.

ScrollableController

class ScrollableController
kotlin.Any
   ↳ androidx.compose.foundation.gestures.ScrollableController

Controller to control the scrollable modifier with. Contains necessary information about the ongoing fling and provides smooth scrolling capabilities.

Summary

Public constructors
<init>(consumeScrollDelta: (Float) -> Float, flingConfig: FlingConfig, animationClock: AnimationClockObservable, interactionState: InteractionState? = null)

Controller to control the scrollable modifier with.

Public methods
Unit
smoothScrollBy(value: Float, spec: AnimationSpec<Float> = SpringSpec(), onEnd: (endReason: AnimationEndReason, finishValue: Float) -> Unit = { _, _ -> })

Smooth scroll by value amount of pixels

Unit

Stop any ongoing animation, smooth scrolling or fling

Properties
Boolean

whether this ScrollableController is currently animating/flinging

Public constructors

<init>

ScrollableController(
    consumeScrollDelta: (Float) -> Float,
    flingConfig: FlingConfig,
    animationClock: AnimationClockObservable,
    interactionState: InteractionState? = null)

Controller to control the scrollable modifier with. Contains necessary information about the ongoing fling and provides smooth scrolling capabilities.

Parameters
consumeScrollDelta: (Float) -> Float callback invoked when drag/fling/smooth scrolling occurs. The callback receives the delta in pixels. Callers should update their state in this lambda and return the amount of delta consumed
flingConfig: FlingConfig fling configuration to use for flinging
animationClock: AnimationClockObservable animation clock to run flinging and smooth scrolling on
interactionState: InteractionState? = null InteractionState that will be updated when this scrollable is being scrolled by dragging, using Interaction.Dragged. If you want to know whether the fling (or smooth scroll) is in progress, use ScrollableController.isAnimationRunning.

Public methods

smoothScrollBy

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

Smooth scroll by value amount of pixels

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

stopAnimation

fun stopAnimation(): Unit

Stop any ongoing animation, smooth scrolling or fling

Call this to stop receiving scrollable deltas in consumeScrollDelta

Properties

isAnimationRunning

val isAnimationRunning: Boolean

whether this ScrollableController is currently animating/flinging