Summary

Public functions

Boolean
canScroll(angle: Float)

Whether this Scrollable2DState can scroll at a given vector angle in rads.

Cmn
Offset

Dispatch scroll delta in pixels in both coordinates avoiding all scroll related mechanisms.

Cmn
suspend Unit
scroll(scrollPriority: MutatePriority, block: suspend Scroll2DScope.() -> Unit)

Call this function to take control of scrolling and gain the ability to send scroll events via Scroll2DScope.scrollBy.

Cmn

Public properties

Boolean

Whether this Scrollable2DState is currently scrolling by gesture, fling or programmatically or not.

Cmn

Extension functions

suspend Offset
Scrollable2DState.animateScrollBy(
    value: Offset,
    animationSpec: AnimationSpec<Offset>
)

Scroll by value pixels with animation.

Cmn
Boolean

If this Scrollable2DState can scroll using the angle in the given offset.

Cmn
suspend Offset

Jump instantly by value pixels.

Cmn
suspend Unit

Stop and suspend until any ongoing animation, smooth scrolling, fling, or any other scroll occurring via ScrollableState.scroll is terminated.

Cmn

Public functions

canScroll

fun canScroll(angle: Float): Boolean

Whether this Scrollable2DState can scroll at a given vector angle in rads. We also provide Scrollable2DState.canScroll(offset: Offset) as an utility for checking against an angle provided through an Offset.

Note that true here does not imply that delta will be consumed - the Scrollable2DState may decide not to handle the incoming delta (such as if it is already being scrolled separately).

dispatchRawDelta

fun dispatchRawDelta(delta: Offset): Offset

Dispatch scroll delta in pixels in both coordinates avoiding all scroll related mechanisms.

NOTE: unlike scroll, dispatching any delta with this method won't trigger nested scroll, won't stop ongoing scroll/drag animation and will bypass scrolling of any priority. This method will also ignore reverseDirection and other parameters set in scrollable.

This method is used internally for nested scrolling dispatch and other low level operations, allowing implementers of Scrollable2DState influence the consumption as suits them. Manually dispatching delta via this method will likely result in a bad user experience, you must prefer scroll method over this one.

Parameters
delta: Offset

amount of scroll dispatched in the nested scroll process in both coordinates

Returns
Offset

the amount of delta consumed in both coordinates

scroll

suspend fun scroll(
    scrollPriority: MutatePriority = MutatePriority.Default,
    block: suspend Scroll2DScope.() -> Unit
): Unit

Call this function to take control of scrolling and gain the ability to send scroll events via Scroll2DScope.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 with the scrollPriority higher or equal to ongoing scroll, ongoing scroll will be canceled.

Public properties

isScrollInProgress

val isScrollInProgressBoolean

Whether this Scrollable2DState is currently scrolling by gesture, fling or programmatically or not.

Extension functions

animateScrollBy

suspend fun Scrollable2DState.animateScrollBy(
    value: Offset,
    animationSpec: AnimationSpec<Offset> = spring()
): Offset

Scroll by value pixels with animation.

Cancels the currently running scroll, if any, and suspends until the cancellation is complete.

Parameters
value: Offset

number of pixels to scroll by

animationSpec: AnimationSpec<Offset> = spring()

AnimationSpec to be used for this scrolling

Returns
Offset

the amount of scroll consumed

fun Scrollable2DState.canScroll(offset: Offset): Boolean

If this Scrollable2DState can scroll using the angle in the given offset.

Parameters
offset: Offset

An offset in pixels representing the 2D vector to check against.

suspend fun Scrollable2DState.scrollBy(value: Offset): Offset

Jump instantly by value pixels.

Cancels the currently running scroll, if any, and suspends until the cancellation is complete.

Parameters
value: Offset

number of pixels to scroll by

Returns
Offset

the amount of scroll consumed

See also
animateScrollBy

for an animated version

suspend fun Scrollable2DState.stopScroll(
    scrollPriority: MutatePriority = MutatePriority.Default
): Unit

Stop and suspend until any ongoing animation, smooth scrolling, fling, or any other scroll occurring via ScrollableState.scroll is terminated.

Parameters
scrollPriority: MutatePriority = MutatePriority.Default

scrolls that run with this priority or lower will be stopped