NestedScrollDispatcher


Nested scroll events dispatcher to notify the nested scroll system about the scrolling events that are happening on the element.

If the element/modifier itself is able to receive scroll events (from the touch, fling, mouse, etc) and it would like to respect nested scrolling by notifying elements above, it should properly dispatch nested scroll events when being scrolled

It is important to dispatch these events at the right time, provide valid information to the parents and react to the feedback received from them in order to provide good user experience with other nested scrolling nodes.

See also
nestedScroll

for the reference of the nested scroll process and more details

NestedScrollConnection

to connect to the nested scroll system

Summary

Public constructors

Cmn

Public functions

suspend Velocity
dispatchPostFling(consumed: Velocity, available: Velocity)

Dispatch post fling pass and suspend until all the interested participants performed velocity process.

Cmn
Offset
dispatchPostScroll(
    consumed: Offset,
    available: Offset,
    source: NestedScrollSource
)

Dispatch nested post-scrolling pass.

Cmn
suspend Velocity

Dispatch pre fling pass and suspend until all the interested participants performed velocity pre consumption.

Cmn
Offset

Dispatch pre scroll pass.

Cmn

Public properties

CoroutineScope

Get the outer coroutine scope to dispatch nested fling on.

Cmn

Public constructors

NestedScrollDispatcher

NestedScrollDispatcher()

Public functions

dispatchPostFling

suspend fun dispatchPostFling(consumed: Velocity, available: Velocity): Velocity

Dispatch post fling pass and suspend until all the interested participants performed velocity process. This triggers NestedScrollConnection.onPostFling on all the ancestors, giving them possibility to react of the velocity that is left after the dispatching node itself flung with the desired amount.

Parameters
consumed: Velocity

velocity already consumed by this node

available: Velocity

velocity that is left for ancestors to consume

Returns
Velocity

velocity that has been consumed by all the ancestors

dispatchPostScroll

fun dispatchPostScroll(
    consumed: Offset,
    available: Offset,
    source: NestedScrollSource
): Offset

Dispatch nested post-scrolling pass. This triggers NestedScrollConnection.onPostScroll on all the ancestors giving them possibility to react of the scroll deltas that are left after the dispatching node itself and other NestedScrollConnections below consumed the desired amount.

Parameters
consumed: Offset

the amount that this node consumed already

available: Offset

the amount of delta left for ancestors

source: NestedScrollSource

source of the scroll

Returns
Offset

the amount of scroll that was consumed by all ancestors

dispatchPreFling

suspend fun dispatchPreFling(available: Velocity): Velocity

Dispatch pre fling pass and suspend until all the interested participants performed velocity pre consumption. This triggers NestedScrollConnection.onPreFling on all the ancestors giving them a possibility to react on the fling that is about to happen and consume part of the velocity.

Parameters
available: Velocity

velocity from the scroll evens that this node is about to fling with

Returns
Velocity

total velocity that is pre-consumed by all ancestors in the chain. This velocity is unavailable for this node to consume, so it should adjust the consumption accordingly

dispatchPreScroll

fun dispatchPreScroll(available: Offset, source: NestedScrollSource): Offset

Dispatch pre scroll pass. This triggers NestedScrollConnection.onPreScroll on all the ancestors giving them possibility to pre-consume delta if they desire so.

Parameters
available: Offset

the delta arrived from a scroll event

source: NestedScrollSource

the source of the scroll event

Returns
Offset

total delta that is pre-consumed by all ancestors in the chain. This delta is unavailable for this node to consume, so it should adjust the consumption accordingly

Public properties

coroutineScope

val coroutineScopeCoroutineScope

Get the outer coroutine scope to dispatch nested fling on.

There might be situations when then component that is dispatching preFling or postFling to parent can be disposed together with its scope, so it's recommended to use launch nested fling dispatch using this scope to prevent abrupt scrolling user experience.

Note: this scope is retrieved from the parent nestedScroll participants, unless the node knows its parent (which is usually after first composition commits), this will throw IllegalStateException.

Throws
kotlin.IllegalStateException

when this field is accessed before the nestedScroll modifier with this NestedScrollDispatcher provided knows its nested scroll parent. Should be safe to access after the initial composition commits.