NestedScrollDispatcher
class 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.
Properties
val coroutineScope: CoroutineScope
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
.
Functions
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 | the delta arrived from a scroll event |
source | the source of the scroll event |
Returns
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 |
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 NestedScrollConnection
s below consumed the desired
amount.
Parameters
consumed | the amount that this node consumed already |
available | the amount of delta left for ancestors |
source | source of the scroll |
Returns
the amount of scroll that was consumed by all ancestors |
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 from the scroll evens that this node is about to fling with |
Returns
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 |
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 already consumed by this node |
available | velocity that is left for ancestors to consume |
Returns
velocity that has been consumed by all the ancestors |