Scrollable2DState

Interface

Common
interface Scrollable2DState

Properties

Common
val isScrollInProgress: Boolean

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

Functions

suspend fun scroll(
        scrollPriority: MutatePriority = MutatePriority.Default,
        block: suspend Scroll2DScope.() -> 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.

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

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

Returns

the amount of delta consumed in both coordinates
fun canScroll(offset: Offset): Boolean

Whether this Scrollable2DState can scroll using offset. This means that this state has enough space to apply offsets on the direction represented by offset. Inferring directionality from offset can be achieved using the angle offered by atan(offset.y, offset.x). Note that returning true here does not imply that offset will be consumed. The Scrollable2DState may decide not to handle the incoming offset (such as if it is already being scrolled separately).

Parameters

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

Returns

Whether this state can scroll in the direction given by offset.