# NestedScrollDispatcher

Artifact: [androidx.compose.ui:ui](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/input/nestedscroll/NestedScrollModifier.kt+class:androidx.compose.ui.input.nestedscroll.NestedScrollDispatcher) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0) Common/All
- Cmn

  ```
  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 |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/nestedscroll/nestedScroll.modifier#(androidx.compose.ui.Modifier).nestedScroll(androidx.compose.ui.input.nestedscroll.NestedScrollConnection,androidx.compose.ui.input.nestedscroll.NestedScrollDispatcher)` | for the reference of the nested scroll process and more details |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/nestedscroll/NestedScrollConnection` | to connect to the nested scroll system |

## Summary

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/nestedscroll/NestedScrollDispatcher#NestedScrollDispatcher()()` | Cmn |

| ### Public functions |
|---|---|---|
| `suspend https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Velocity` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/nestedscroll/NestedScrollDispatcher#dispatchPostFling(androidx.compose.ui.unit.Velocity,androidx.compose.ui.unit.Velocity)(consumed: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Velocity, available: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Velocity)` Dispatch post fling pass and suspend until all the interested participants performed velocity process. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/nestedscroll/NestedScrollDispatcher#dispatchPostScroll(androidx.compose.ui.geometry.Offset,androidx.compose.ui.geometry.Offset,androidx.compose.ui.input.nestedscroll.NestedScrollSource)( consumed: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset, available: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset, source: https://developer.android.com/reference/kotlin/androidx/compose/ui/input/nestedscroll/NestedScrollSource )` Dispatch nested post-scrolling pass. | Cmn |
| `suspend https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Velocity` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/nestedscroll/NestedScrollDispatcher#dispatchPreFling(androidx.compose.ui.unit.Velocity)(available: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Velocity)` Dispatch pre fling pass and suspend until all the interested participants performed velocity pre consumption. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/nestedscroll/NestedScrollDispatcher#dispatchPreScroll(androidx.compose.ui.geometry.Offset,androidx.compose.ui.input.nestedscroll.NestedScrollSource)(available: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset, source: https://developer.android.com/reference/kotlin/androidx/compose/ui/input/nestedscroll/NestedScrollSource)` Dispatch pre scroll pass. | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/nestedscroll/NestedScrollDispatcher#coroutineScope()` Get the outer coroutine scope to dispatch nested fling on. | Cmn |

## Public constructors

### NestedScrollDispatcher

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
NestedScrollDispatcher()
```

## Public functions

### dispatchPostFling

Cmn

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

Dispatch post fling pass and suspend until all the interested participants performed velocity process. This triggers `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/nestedscroll/NestedScrollConnection#onPostFling(androidx.compose.ui.unit.Velocity,androidx.compose.ui.unit.Velocity)` 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: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Velocity` | velocity already consumed by this node |
| `available: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Velocity` | velocity that is left for ancestors to consume |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Velocity` | velocity that has been consumed by all the ancestors |

### dispatchPostScroll

Cmn Added in [1.10.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.10.0)

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

Dispatch nested post-scrolling pass. This triggers `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/nestedscroll/NestedScrollConnection#onPostScroll(androidx.compose.ui.geometry.Offset,androidx.compose.ui.geometry.Offset,androidx.compose.ui.input.nestedscroll.NestedScrollSource)` on all the ancestors giving them possibility to react of the scroll deltas that are left after the dispatching node itself and other `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/nestedscroll/NestedScrollConnection`s below consumed the desired amount.

| Parameters |
|---|---|
| `consumed: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | the amount that this node consumed already |
| `available: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | the amount of delta left for ancestors |
| `source: https://developer.android.com/reference/kotlin/androidx/compose/ui/input/nestedscroll/NestedScrollSource` | source of the scroll |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | the amount of scroll that was consumed by all ancestors |

### dispatchPreFling

Cmn

```
suspend fun dispatchPreFling(available: Velocity): Velocity
```

Dispatch pre fling pass and suspend until all the interested participants performed velocity pre consumption. This triggers `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/nestedscroll/NestedScrollConnection#onPreFling(androidx.compose.ui.unit.Velocity)` 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: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Velocity` | velocity from the scroll evens that this node is about to fling with |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/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

Cmn Added in [1.10.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.10.0)

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

Dispatch pre scroll pass. This triggers `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/nestedscroll/NestedScrollConnection#onPreScroll(androidx.compose.ui.geometry.Offset,androidx.compose.ui.input.nestedscroll.NestedScrollSource)` on all the ancestors giving them possibility to pre-consume delta if they desire so.

| Parameters |
|---|---|
| `available: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | the delta arrived from a scroll event |
| `source: https://developer.android.com/reference/kotlin/androidx/compose/ui/input/nestedscroll/NestedScrollSource` | the source of the scroll event |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/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

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
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 return a cancelled `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html`.