{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

NestedScrollDispatcher

public final 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.

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

Public methods

final @NonNull Velocity

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

final @NonNull Offset
dispatchPostScroll(
    @NonNull Offset consumed,
    @NonNull Offset available,
    @NonNull NestedScrollSource source
)

Dispatch nested post-scrolling pass.

final @NonNull Velocity

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

final @NonNull Offset
dispatchPreScroll(
    @NonNull Offset available,
    @NonNull NestedScrollSource source
)

Dispatch pre scroll pass.

final @NonNull <Error class: unknown class>

Public constructors

NestedScrollDispatcher

public NestedScrollDispatcher()

Public methods

dispatchPostFling

public final @NonNull Velocity dispatchPostFling(@NonNull Velocity consumed, @NonNull Velocity available)

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
@NonNull Velocity consumed

velocity already consumed by this node

@NonNull Velocity available

velocity that is left for ancestors to consume

Returns
@NonNull Velocity

velocity that has been consumed by all the ancestors

dispatchPostScroll

public final @NonNull Offset dispatchPostScroll(
    @NonNull Offset consumed,
    @NonNull Offset available,
    @NonNull NestedScrollSource source
)

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
@NonNull Offset consumed

the amount that this node consumed already

@NonNull Offset available

the amount of delta left for ancestors

@NonNull NestedScrollSource source

source of the scroll

Returns
@NonNull Offset

the amount of scroll that was consumed by all ancestors

dispatchPreFling

public final @NonNull Velocity dispatchPreFling(@NonNull Velocity available)

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
@NonNull Velocity available

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

Returns
@NonNull 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

public final @NonNull Offset dispatchPreScroll(
    @NonNull Offset available,
    @NonNull NestedScrollSource source
)

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

Parameters
@NonNull Offset available

the delta arrived from a scroll event

@NonNull NestedScrollSource source

the source of the scroll event

Returns
@NonNull 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

getCoroutineScope

public final @NonNull <Error class: unknown class> getCoroutineScope()
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.