# Scrollable2DState

Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/gestures/Scrollable2DState.kt+class:androidx.compose.foundation.gestures.Scrollable2DState) Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.9.0) Common/AllAndroid/JVM
- Cmn

  ```
  interface Scrollable2DState
  ```

*** ** * ** ***

## Summary

| ### Public functions |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/Scrollable2DState#canScroll(androidx.compose.ui.geometry.Offset)(offset: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset)` Whether this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/Scrollable2DState` can scroll using `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/Scrollable2DState#canScroll(androidx.compose.ui.geometry.Offset)`. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/Scrollable2DState#dispatchRawDelta(androidx.compose.ui.geometry.Offset)(delta: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset)` Dispatch scroll delta in pixels in both coordinates avoiding all scroll related mechanisms. | Cmn |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/Scrollable2DState#scroll(androidx.compose.foundation.MutatePriority,kotlin.coroutines.SuspendFunction1)(scrollPriority: https://developer.android.com/reference/kotlin/androidx/compose/foundation/MutatePriority, block: suspend https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/Scroll2DScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Call this function to take control of scrolling and gain the ability to send scroll events via `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/Scroll2DScope#scrollBy(androidx.compose.ui.geometry.Offset)`. | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/Scrollable2DState#isScrollInProgress()` Whether this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/Scrollable2DState` is currently scrolling by gesture, fling or programmatically or not. | Cmn |

| ### Extension functions |
|---|---|---|
| `suspend https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/Scrollable2DState.https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/Scrollable2DState#(androidx.compose.foundation.gestures.Scrollable2DState).animateScrollBy(androidx.compose.ui.geometry.Offset,androidx.compose.animation.core.AnimationSpec)( value: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset, animationSpec: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationSpec<https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset> )` Scroll by `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.foundation.gestures.Scrollable2DState).animateScrollBy(androidx.compose.ui.geometry.Offset,androidx.compose.animation.core.AnimationSpec)` pixels with animation. | Cmn |
| `suspend https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/Scrollable2DState.https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/Scrollable2DState#(androidx.compose.foundation.gestures.Scrollable2DState).scrollBy(androidx.compose.ui.geometry.Offset)(value: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset)` Jump instantly by `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.foundation.gestures.Scrollable2DState).scrollBy(androidx.compose.ui.geometry.Offset)` pixels. | Cmn |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/Scrollable2DState.https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/Scrollable2DState#(androidx.compose.foundation.gestures.Scrollable2DState).stopScroll(androidx.compose.foundation.MutatePriority)(scrollPriority: https://developer.android.com/reference/kotlin/androidx/compose/foundation/MutatePriority)` Stop and suspend until any ongoing animation, smooth scrolling, fling, or any other scroll occurring via `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollableState#scroll(androidx.compose.foundation.MutatePriority,kotlin.coroutines.SuspendFunction1)` is terminated. | Cmn |

## Public functions

### canScroll

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

```
fun canScroll(offset: Offset): Boolean
```

Whether this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/Scrollable2DState` can scroll using `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/Scrollable2DState#canScroll(androidx.compose.ui.geometry.Offset)`. This means that this state has enough space to apply offsets on the direction represented by `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/Scrollable2DState#canScroll(androidx.compose.ui.geometry.Offset)`. Inferring directionality from `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/Scrollable2DState#canScroll(androidx.compose.ui.geometry.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 |
|---|---|
| `offset: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | An offset in pixels representing the 2D vector to check against. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether this state can scroll in the direction given by `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/Scrollable2DState#canScroll(androidx.compose.ui.geometry.Offset)`. |

### dispatchRawDelta

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

```
fun dispatchRawDelta(delta: Offset): Offset
```

Dispatch scroll delta in pixels in both coordinates avoiding all scroll related mechanisms.

**NOTE:** unlike `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/Scrollable2DState#scroll(androidx.compose.foundation.MutatePriority,kotlin.coroutines.SuspendFunction1)`, 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 `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/Scrollable2DState` influence the consumption as suits them. Manually dispatching delta via this method will likely result in a bad user experience, you must prefer `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/Scrollable2DState#scroll(androidx.compose.foundation.MutatePriority,kotlin.coroutines.SuspendFunction1)` method over this one.

| Parameters |
|---|---|
| `delta: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | amount of scroll dispatched in the nested scroll process in both coordinates |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | the amount of delta consumed in both coordinates |

### scroll

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

```
suspend fun scroll(
    scrollPriority: MutatePriority = MutatePriority.Default,
    block: suspend Scroll2DScope.() -> Unit
): Unit
```

Call this function to take control of scrolling and gain the ability to send scroll events via `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/Scroll2DScope#scrollBy(androidx.compose.ui.geometry.Offset)`. All actions that change the logical scroll position must be performed within a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/Scrollable2DState#scroll(androidx.compose.foundation.MutatePriority,kotlin.coroutines.SuspendFunction1)` block (even if they don't call any other methods on this object) in order to guarantee that mutual exclusion is enforced.

If `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/Scrollable2DState#scroll(androidx.compose.foundation.MutatePriority,kotlin.coroutines.SuspendFunction1)` is called from elsewhere with the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/Scrollable2DState#scroll(androidx.compose.foundation.MutatePriority,kotlin.coroutines.SuspendFunction1)` higher or equal to ongoing scroll, ongoing scroll will be canceled.

## Public properties

### isScrollInProgress

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

```
val isScrollInProgress: Boolean
```

Whether this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/Scrollable2DState` is currently scrolling by gesture, fling or programmatically or not.

## Extension functions

### Scrollable2DState.animateScrollBy

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/gestures/ScrollExtensions.kt+function:animateScrollBy)

```
suspend fun Scrollable2DState.animateScrollBy(
    value: Offset,
    animationSpec: AnimationSpec<Offset> = spring()
): Offset
```

Scroll by `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.foundation.gestures.Scrollable2DState).animateScrollBy(androidx.compose.ui.geometry.Offset,androidx.compose.animation.core.AnimationSpec)` pixels with animation.

Cancels the currently running scroll, if any, and suspends until the cancellation is complete.

| Parameters |
|---|---|
| `value: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | number of pixels to scroll by |
| `animationSpec: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationSpec<https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset> = spring()` | `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationSpec` to be used for this scrolling |

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

### Scrollable2DState.scrollBy

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/gestures/ScrollExtensions.kt+function:scrollBy)

```
suspend fun Scrollable2DState.scrollBy(value: Offset): Offset
```

Jump instantly by `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.foundation.gestures.Scrollable2DState).scrollBy(androidx.compose.ui.geometry.Offset)` pixels.

Cancels the currently running scroll, if any, and suspends until the cancellation is complete.

| Parameters |
|---|---|
| `value: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | number of pixels to scroll by |

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

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.foundation.gestures.ScrollableState).animateScrollBy(kotlin.Float,androidx.compose.animation.core.AnimationSpec)` | for an animated version |

### Scrollable2DState.stopScroll

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/gestures/ScrollExtensions.kt+function:stopScroll)

```
suspend fun Scrollable2DState.stopScroll(
    scrollPriority: MutatePriority = MutatePriority.Default
): Unit
```

Stop and suspend until any ongoing animation, smooth scrolling, fling, or any other scroll occurring via `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollableState#scroll(androidx.compose.foundation.MutatePriority,kotlin.coroutines.SuspendFunction1)` is terminated.

| Parameters |
|---|---|
| `scrollPriority: https://developer.android.com/reference/kotlin/androidx/compose/foundation/MutatePriority = MutatePriority.Default` | scrolls that run with this priority or lower will be stopped |