# PagerState

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/pager/PagerState.kt+class:androidx.compose.foundation.pager.PagerState) Added in [1.4.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.4.0) Common/All
- Cmn

  ```
  abstract class PagerState : ScrollableState
  ```

*** ** * ** ***

The state that can be used to control `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/VerticalPager.composable#VerticalPager(androidx.compose.foundation.pager.PagerState,androidx.compose.ui.Modifier,androidx.compose.foundation.layout.PaddingValues,androidx.compose.foundation.pager.PageSize,kotlin.Int,androidx.compose.ui.unit.Dp,androidx.compose.ui.Alignment.Horizontal,androidx.compose.foundation.gestures.TargetedFlingBehavior,kotlin.Boolean,kotlin.Boolean,kotlin.Function1,androidx.compose.ui.input.nestedscroll.NestedScrollConnection,androidx.compose.foundation.gestures.snapping.SnapPosition,androidx.compose.foundation.OverscrollEffect,androidx.compose.foundation.gestures.BringIntoViewSpec,kotlin.Function2)` and `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/HorizontalPager.composable#HorizontalPager(androidx.compose.foundation.pager.PagerState,androidx.compose.ui.Modifier,androidx.compose.foundation.layout.PaddingValues,androidx.compose.foundation.pager.PageSize,kotlin.Int,androidx.compose.ui.unit.Dp,androidx.compose.ui.Alignment.Vertical,androidx.compose.foundation.gestures.TargetedFlingBehavior,kotlin.Boolean,kotlin.Boolean,kotlin.Function1,androidx.compose.ui.input.nestedscroll.NestedScrollConnection,androidx.compose.foundation.gestures.snapping.SnapPosition,androidx.compose.foundation.OverscrollEffect,androidx.compose.foundation.gestures.BringIntoViewSpec,kotlin.Function2)`

## Summary

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#PagerState(kotlin.Int,kotlin.Float)( currentPage: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, currentPageOffsetFraction: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = -0.5, to = 0.5) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html )` | Cmn |

| ### Public functions |
|---|---|---|
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#animateScrollToPage(kotlin.Int,kotlin.Float,androidx.compose.animation.core.AnimationSpec)( page: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, pageOffsetFraction: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = -0.5, to = 0.5) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, animationSpec: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationSpec<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html> )` Scroll animate to a given `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#animateScrollToPage(kotlin.Int,kotlin.Float,androidx.compose.animation.core.AnimationSpec)`'s closest snap position. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#dispatchRawDelta(kotlin.Float)(delta: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Dispatch scroll delta in pixels avoiding all scroll related mechanisms. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#getOffsetDistanceInPages(kotlin.Int)(page: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` An utility function to help to calculate a given page's offset. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#requestScrollToPage(kotlin.Int,kotlin.Float)( page: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, pageOffsetFraction: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = -0.5, to = 0.5) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html )` Requests the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#requestScrollToPage(kotlin.Int,kotlin.Float)` to be at the snapped position during the next remeasure, offset by `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#requestScrollToPage(kotlin.Int,kotlin.Float)`, and schedules a remeasure. | Cmn |
| `open suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#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/ScrollScope.() -> 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/ScrollScope#scrollBy(kotlin.Float)`. | Cmn |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#scrollToPage(kotlin.Int,kotlin.Float)( page: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, pageOffsetFraction: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = -0.5, to = 0.5) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html )` Scroll (jump immediately) to a given `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#scrollToPage(kotlin.Int,kotlin.Float)`. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollScope.https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#(androidx.compose.foundation.gestures.ScrollScope).updateCurrentPage(kotlin.Int,kotlin.Float)( page: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, pageOffsetFraction: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = -0.5, to = 0.5) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html )` Jump immediately to a given `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#(androidx.compose.foundation.gestures.ScrollScope).updateCurrentPage(kotlin.Int,kotlin.Float)` with a given `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#(androidx.compose.foundation.gestures.ScrollScope).updateCurrentPage(kotlin.Int,kotlin.Float)` inside a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollScope`. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollScope.https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#(androidx.compose.foundation.gestures.ScrollScope).updateTargetPage(kotlin.Int)(targetPage: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Used to update `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#(androidx.compose.foundation.gestures.ScrollScope).updateTargetPage(kotlin.Int)` during a programmatic scroll operation. | Cmn |

| ### Public properties |
|---|---|---|
| `final https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#canScrollBackward()` Whether this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollableState` can scroll backward (consume a negative delta). | Cmn |
| `final https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#canScrollForward()` Whether this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollableState` can scroll forward (consume a positive delta). | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#currentPage()` The page that sits closest to the snapped position. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#currentPageOffsetFraction()` Indicates how far the current page is to the snapped position, this will vary from -0.5 (page is offset towards the start of the layout) to 0.5 (page is offset towards the end of the layout). | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/InteractionSource` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#interactionSource()` `https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/InteractionSource` that will be used to dispatch drag events when this list is being dragged. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#isScrollInProgress()` Whether this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollableState` is currently scrolling by gesture, fling or programmatically or not. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#lastScrolledBackward()` The value of this property is true under the following scenarios, otherwise it's false. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#lastScrolledForward()` The value of this property is true under the following scenarios, otherwise it's false. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerLayoutInfo` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#layoutInfo()` A `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerLayoutInfo` that contains useful information about the Pager's last layout pass. | Cmn |
| `abstract https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#pageCount()` The total amount of pages present in this pager. | Cmn |
| `open https://developer.android.com/reference/kotlin/androidx/compose/foundation/ScrollIndicatorState?` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#scrollIndicatorState()` `https://developer.android.com/reference/kotlin/androidx/compose/foundation/ScrollIndicatorState` used for drawing a scroll indicator (e.g., a scrollbar). | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#settledPage()` The page that is currently "settled". | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#targetPage()` The page this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/package-summary#Pager(androidx.compose.ui.Modifier,androidx.compose.foundation.pager.PagerState,androidx.compose.foundation.layout.PaddingValues,kotlin.Boolean,androidx.compose.foundation.gestures.Orientation,androidx.compose.foundation.gestures.TargetedFlingBehavior,kotlin.Boolean,androidx.compose.foundation.OverscrollEffect,kotlin.Int,androidx.compose.ui.unit.Dp,androidx.compose.foundation.pager.PageSize,androidx.compose.ui.input.nestedscroll.NestedScrollConnection,kotlin.Function1,androidx.compose.ui.Alignment.Horizontal,androidx.compose.ui.Alignment.Vertical,androidx.compose.foundation.gestures.snapping.SnapPosition,androidx.compose.foundation.gestures.BringIntoViewSpec,kotlin.Function2)` intends to settle to. | Cmn |

## Public constructors

### PagerState

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

```
PagerState(
    currentPage: Int = 0,
    currentPageOffsetFraction: @FloatRange(from = -0.5, to = 0.5) Float = 0.0f
)
```

| Parameters |
|---|---|
| `currentPage: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = 0` | The initial page to be displayed |
| `currentPageOffsetFraction: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = -0.5, to = 0.5) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html = 0.0f` | The offset of the initial page with respect to the start of the layout. |

## Public functions

### animateScrollToPage

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

```
suspend fun animateScrollToPage(
    page: Int,
    pageOffsetFraction: @FloatRange(from = -0.5, to = 0.5) Float = 0.0f,
    animationSpec: AnimationSpec<Float> = spring()
): Unit
```

Scroll animate to a given `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#animateScrollToPage(kotlin.Int,kotlin.Float,androidx.compose.animation.core.AnimationSpec)`'s closest snap position. If the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#animateScrollToPage(kotlin.Int,kotlin.Float,androidx.compose.animation.core.AnimationSpec)` is too far away from `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#currentPage()` we will not compose all pages in the way. We will pre-jump to a nearer page, compose and animate the rest of the pages until `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#animateScrollToPage(kotlin.Int,kotlin.Float,androidx.compose.animation.core.AnimationSpec)`.

Please refer to the sample to learn how to use this API.

```kotlin
import androidx.compose.animation.core.animate
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.PagerState
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

val state = rememberPagerState { 10 }
val animationScope = rememberCoroutineScope()
Column {
    HorizontalPager(modifier = Modifier.weight(0.7f), state = state) { page ->
        Box(
            modifier =
                Modifier.padding(10.dp).background(Color.Blue).fillMaxWidth().aspectRatio(1f),
            contentAlignment = Alignment.Center,
        ) {
            Text(text = page.toString(), fontSize = 32.sp)
        }
    }

    Box(modifier = Modifier.weight(0.3f).fillMaxWidth(), contentAlignment = Alignment.Center) {
        Button(
            onClick = {
                animationScope.launch { state.animateScrollToPage(state.currentPage + 1) }
            }
        ) {
            Text(text = "Next Page")
        }
    }
}
```

| Parameters |
|---|---|
| `page: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The destination page to scroll to |
| `pageOffsetFraction: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = -0.5, to = 0.5) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html = 0.0f` | A fraction of the page size that indicates the offset the destination page will be offset from its snapped position. |
| `animationSpec: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationSpec<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html> = spring()` | An `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationSpec` to move between pages. We'll use a `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/package-summary#spring(kotlin.Float,kotlin.Float,kotlin.Any)` as the default animation. |

### dispatchRawDelta

Cmn

```
open fun dispatchRawDelta(delta: Float): Float
```

Dispatch scroll delta in pixels avoiding all scroll related mechanisms.

**NOTE:** unlike `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollableState#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/ScrollableState` 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/ScrollableState#scroll(androidx.compose.foundation.MutatePriority,kotlin.coroutines.SuspendFunction1)` method over this one.

| Parameters |
|---|---|
| `delta: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | amount of scroll dispatched in the nested scroll process |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | the amount of delta consumed |

### getOffsetDistanceInPages

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

```
fun getOffsetDistanceInPages(page: Int): Float
```

An utility function to help to calculate a given page's offset. This is an offset that represents how far `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#getOffsetDistanceInPages(kotlin.Int)` is from the settled position (represented by `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#currentPage()` offset). The difference here is that `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#currentPageOffsetFraction()` is a value between -0.5 and 0.5 and the value calculated by this function can be larger than these numbers if `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#getOffsetDistanceInPages(kotlin.Int)` is different than `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#currentPage()`.

For instance, if currentPage=0 and we call `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#getOffsetDistanceInPages(kotlin.Int)` for page 3, the result will be 3, meaning the given page is 3 pages away from the current page (the sign represent the direction of the offset, positive is forward, negative is backwards). Another example is if currentPage=3 and we call `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#getOffsetDistanceInPages(kotlin.Int)` for page 1, the result would be -2, meaning we're 2 pages away (moving backwards) to the current page.

This offset also works in conjunction with `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#currentPageOffsetFraction()`, so if `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#currentPage()` is out of its snapped position (i.e. currentPageOffsetFraction!=0) then the calculated value will still represent the offset in number of pages (in this case, not whole pages). For instance, if currentPage=1 and we're slightly offset, currentPageOffsetFraction=0.2, if we call this to page 2, the result would be 0.8, that is 0.8 page away from current page (moving forward).

| Parameters |
|---|---|
| `page: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The page to calculate the offset from. This should be between 0 and `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#pageCount()`. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The offset of `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#getOffsetDistanceInPages(kotlin.Int)` with respect to `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#currentPage()`. |

### requestScrollToPage

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

```
fun requestScrollToPage(
    page: @IntRange(from = 0) Int,
    pageOffsetFraction: @FloatRange(from = -0.5, to = 0.5) Float = 0.0f
): Unit
```

Requests the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#requestScrollToPage(kotlin.Int,kotlin.Float)` to be at the snapped position during the next remeasure, offset by `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#requestScrollToPage(kotlin.Int,kotlin.Float)`, and schedules a remeasure.

The scroll position will be updated to the requested position rather than maintain the index based on the current page key (when a data set change will also be applied during the next remeasure), but *only* for the next remeasure.

Any scroll in progress will be cancelled.

| Parameters |
|---|---|
| `page: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the index to which to scroll. Must be non-negative. |
| `pageOffsetFraction: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = -0.5, to = 0.5) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html = 0.0f` | the offset fraction that the page should end up after the scroll. |

### scroll

Cmn

```
open suspend fun scroll(
    scrollPriority: MutatePriority = MutatePriority.Default,
    block: suspend ScrollScope.() -> 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/ScrollScope#scrollBy(kotlin.Float)`. All actions that change the logical scroll position must be performed within a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollableState#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/ScrollableState#scroll(androidx.compose.foundation.MutatePriority,kotlin.coroutines.SuspendFunction1)` is called from elsewhere with the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollableState#scroll(androidx.compose.foundation.MutatePriority,kotlin.coroutines.SuspendFunction1)` higher or equal to ongoing scroll, ongoing scroll will be canceled.

### scrollToPage

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

```
suspend fun scrollToPage(
    page: Int,
    pageOffsetFraction: @FloatRange(from = -0.5, to = 0.5) Float = 0.0f
): Unit
```

Scroll (jump immediately) to a given `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#scrollToPage(kotlin.Int,kotlin.Float)`.

Please refer to the sample to learn how to use this API.

```kotlin
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.PagerState
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

val state = rememberPagerState { 10 }
val scrollScope = rememberCoroutineScope()
Column {
    HorizontalPager(modifier = Modifier.height(400.dp), state = state) { page ->
        Box(
            modifier =
                Modifier.padding(10.dp).background(Color.Blue).fillMaxWidth().aspectRatio(1f),
            contentAlignment = Alignment.Center,
        ) {
            Text(text = page.toString(), fontSize = 32.sp)
        }
    }

    Box(modifier = Modifier.fillMaxWidth(), contentAlignment = Alignment.Center) {
        Button(onClick = { scrollScope.launch { state.scrollToPage(state.currentPage + 1) } }) {
            Text(text = "Next Page")
        }
    }
}
```

| Parameters |
|---|---|
| `page: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The destination page to scroll to |
| `pageOffsetFraction: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = -0.5, to = 0.5) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html = 0.0f` | A fraction of the page size that indicates the offset the destination page will be offset from its snapped position. |

### ScrollScope.updateCurrentPage

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/pager/PagerState.kt+function:updateCurrentPage) Added in [1.6.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.6.0)

```
fun ScrollScope.updateCurrentPage(
    page: Int,
    pageOffsetFraction: @FloatRange(from = -0.5, to = 0.5) Float = 0.0f
): Unit
```

Jump immediately to a given `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#(androidx.compose.foundation.gestures.ScrollScope).updateCurrentPage(kotlin.Int,kotlin.Float)` with a given `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#(androidx.compose.foundation.gestures.ScrollScope).updateCurrentPage(kotlin.Int,kotlin.Float)` inside a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollScope`. Use this method to create custom animated scrolling experiences. This will update the value of `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#currentPage()` and `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#currentPageOffsetFraction()` immediately, but can only be used inside a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollScope`, use `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#scroll(androidx.compose.foundation.MutatePriority,kotlin.coroutines.SuspendFunction1)` to gain access to a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollScope`.

Please refer to the sample to learn how to use this API.

```kotlin
import androidx.compose.animation.core.animate
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.PagerState
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

suspend fun PagerState.customAnimateScrollToPage(page: Int) {
    val preJumpPosition =
        if (page > currentPage) {
            (page - 1).coerceAtLeast(0)
        } else {
            (page + 1).coerceAtMost(pageCount)
        }
    scroll {
        // Update the target page
        updateTargetPage(page)

        // pre-jump to 1 page before our target page
        updateCurrentPage(preJumpPosition, 0.0f)
        val targetPageDiff = page - currentPage
        val distance = targetPageDiff * layoutInfo.pageSize.toFloat()
        var previousValue = 0.0f
        animate(0f, distance) { currentValue, _ ->
            previousValue += scrollBy(currentValue - previousValue)
        }
    }
}

val state = rememberPagerState(initialPage = 5) { 10 }
val scope = rememberCoroutineScope()

Column {
    HorizontalPager(modifier = Modifier.fillMaxSize().weight(0.9f), state = state) { page ->
        Box(
            modifier =
                Modifier.padding(10.dp).background(Color.Blue).fillMaxWidth().aspectRatio(1f),
            contentAlignment = Alignment.Center,
        ) {
            Text(text = page.toString(), fontSize = 32.sp)
        }
    }

    Button(onClick = { scope.launch { state.customAnimateScrollToPage(1) } }) {
        Text(text = "Jump to Page 1")
    }
}
```

| Parameters |
|---|---|
| `page: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The destination page to scroll to |
| `pageOffsetFraction: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = -0.5, to = 0.5) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html = 0.0f` | A fraction of the page size that indicates the offset the destination page will be offset from its snapped position. |

### ScrollScope.updateTargetPage

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/pager/PagerState.kt+function:updateTargetPage) Added in [1.6.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.6.0)

```
fun ScrollScope.updateTargetPage(targetPage: Int): Unit
```

Used to update `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#(androidx.compose.foundation.gestures.ScrollScope).updateTargetPage(kotlin.Int)` during a programmatic scroll operation. This can only be called inside a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollScope` and should be called anytime a custom scroll (through `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#scroll(androidx.compose.foundation.MutatePriority,kotlin.coroutines.SuspendFunction1)`) is executed in order to correctly update `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#(androidx.compose.foundation.gestures.ScrollScope).updateTargetPage(kotlin.Int)`. This will not move the pages and it's still the responsibility of the caller to call `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollScope#scrollBy(kotlin.Float)` in order to actually get to `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#(androidx.compose.foundation.gestures.ScrollScope).updateTargetPage(kotlin.Int)`. By the end of the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#scroll(androidx.compose.foundation.MutatePriority,kotlin.coroutines.SuspendFunction1)` block, when the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/package-summary#Pager(androidx.compose.ui.Modifier,androidx.compose.foundation.pager.PagerState,androidx.compose.foundation.layout.PaddingValues,kotlin.Boolean,androidx.compose.foundation.gestures.Orientation,androidx.compose.foundation.gestures.TargetedFlingBehavior,kotlin.Boolean,androidx.compose.foundation.OverscrollEffect,kotlin.Int,androidx.compose.ui.unit.Dp,androidx.compose.foundation.pager.PageSize,androidx.compose.ui.input.nestedscroll.NestedScrollConnection,kotlin.Function1,androidx.compose.ui.Alignment.Horizontal,androidx.compose.ui.Alignment.Vertical,androidx.compose.foundation.gestures.snapping.SnapPosition,androidx.compose.foundation.gestures.BringIntoViewSpec,kotlin.Function2)` is no longer scrolling `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#(androidx.compose.foundation.gestures.ScrollScope).updateTargetPage(kotlin.Int)` will assume the value of `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#currentPage()`.

Please refer to the sample to learn how to use this API.

```kotlin
import androidx.compose.animation.core.animate
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.PagerState
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

suspend fun PagerState.customAnimateScrollToPage(page: Int) {
    val preJumpPosition =
        if (page > currentPage) {
            (page - 1).coerceAtLeast(0)
        } else {
            (page + 1).coerceAtMost(pageCount)
        }
    scroll {
        // Update the target page
        updateTargetPage(page)

        // pre-jump to 1 page before our target page
        updateCurrentPage(preJumpPosition, 0.0f)
        val targetPageDiff = page - currentPage
        val distance = targetPageDiff * layoutInfo.pageSize.toFloat()
        var previousValue = 0.0f
        animate(0f, distance) { currentValue, _ ->
            previousValue += scrollBy(currentValue - previousValue)
        }
    }
}

val state = rememberPagerState(initialPage = 5) { 10 }
val scope = rememberCoroutineScope()

Column {
    HorizontalPager(modifier = Modifier.fillMaxSize().weight(0.9f), state = state) { page ->
        Box(
            modifier =
                Modifier.padding(10.dp).background(Color.Blue).fillMaxWidth().aspectRatio(1f),
            contentAlignment = Alignment.Center,
        ) {
            Text(text = page.toString(), fontSize = 32.sp)
        }
    }

    Button(onClick = { scope.launch { state.customAnimateScrollToPage(1) } }) {
        Text(text = "Jump to Page 1")
    }
}
```

## Public properties

### canScrollBackward

Cmn

```
final val canScrollBackward: Boolean
```

Whether this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollableState` can scroll backward (consume a negative delta). This is typically false if the scroll position is equal to its minimum value, and true otherwise.

Note that `true` here does not imply that delta *will* be consumed - the ScrollableState may decide not to handle the incoming delta (such as if it is already being scrolled separately). Additionally, for backwards compatibility with previous versions of ScrollableState this value defaults to `true`.

```kotlin
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.KeyboardArrowDown
import androidx.compose.material.icons.filled.KeyboardArrowUp
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.graphicsLayer

val state = rememberLazyListState()
Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
    Icon(
        Icons.Filled.KeyboardArrowUp,
        null,
        Modifier.graphicsLayer {
            // Hide the icon if we cannot scroll backward (we are the start of the list)
            // We use graphicsLayer here to control the alpha so that we only redraw when this
            // value changes, instead of recomposing
            alpha = if (state.canScrollBackward) 1f else 0f
        },
        Color.Red,
    )
    val items = (1..100).toList()
    LazyColumn(Modifier.weight(1f).fillMaxWidth(), state) {
        items(items) { Text("Item is $it") }
    }
    Icon(
        Icons.Filled.KeyboardArrowDown,
        null,
        Modifier.graphicsLayer {
            // Hide the icon if we cannot scroll forward (we are the end of the list)
            // We use graphicsLayer here to control the alpha so that we only redraw when this
            // value changes, instead of recomposing
            alpha = if (state.canScrollForward) 1f else 0f
        },
        Color.Red,
    )
}
```

### canScrollForward

Cmn

```
final val canScrollForward: Boolean
```

Whether this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollableState` can scroll forward (consume a positive delta). This is typically false if the scroll position is equal to its maximum value, and true otherwise.

Note that `true` here does not imply that delta *will* be consumed - the ScrollableState may decide not to handle the incoming delta (such as if it is already being scrolled separately). Additionally, for backwards compatibility with previous versions of ScrollableState this value defaults to `true`.

```kotlin
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.KeyboardArrowDown
import androidx.compose.material.icons.filled.KeyboardArrowUp
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.graphicsLayer

val state = rememberLazyListState()
Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
    Icon(
        Icons.Filled.KeyboardArrowUp,
        null,
        Modifier.graphicsLayer {
            // Hide the icon if we cannot scroll backward (we are the start of the list)
            // We use graphicsLayer here to control the alpha so that we only redraw when this
            // value changes, instead of recomposing
            alpha = if (state.canScrollBackward) 1f else 0f
        },
        Color.Red,
    )
    val items = (1..100).toList()
    LazyColumn(Modifier.weight(1f).fillMaxWidth(), state) {
        items(items) { Text("Item is $it") }
    }
    Icon(
        Icons.Filled.KeyboardArrowDown,
        null,
        Modifier.graphicsLayer {
            // Hide the icon if we cannot scroll forward (we are the end of the list)
            // We use graphicsLayer here to control the alpha so that we only redraw when this
            // value changes, instead of recomposing
            alpha = if (state.canScrollForward) 1f else 0f
        },
        Color.Red,
    )
}
```

### currentPage

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

```
val currentPage: Int
```

The page that sits closest to the snapped position. This is an observable value and will change as the pager scrolls either by gesture or animation.

Please refer to the sample to learn how to use this API.

```kotlin
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.PagerState
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material3.Text
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

val pagerState = rememberPagerState { 10 }
Column(modifier = Modifier.fillMaxSize()) {
    HorizontalPager(modifier = Modifier.weight(0.9f), state = pagerState) { page ->
        Box(
            modifier =
                Modifier.padding(10.dp).background(Color.Blue).fillMaxWidth().aspectRatio(1f),
            contentAlignment = Alignment.Center,
        ) {
            Text(text = page.toString(), fontSize = 32.sp)
        }
    }
    Column(modifier = Modifier.weight(0.1f).fillMaxWidth()) {
        Text(text = "Current Page: ${pagerState.currentPage}")
        Text(text = "Current Page Offset Fraction: ${pagerState.currentPageOffsetFraction}")
        Text(text = "Target Page: ${pagerState.targetPage}")
        Text(text = "Settled Page Offset: ${pagerState.settledPage}")
    }
}
```

### currentPageOffsetFraction

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

```
val currentPageOffsetFraction: Float
```

Indicates how far the current page is to the snapped position, this will vary from -0.5 (page is offset towards the start of the layout) to 0.5 (page is offset towards the end of the layout). This is 0.0 if the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#currentPage()` is in the snapped position. The value will flip once the current page changes.

This property is observable and shouldn't be used as is in a composable function due to potential performance issues. To use it in the composition, please consider using a derived state (e.g `https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#derivedStateOf(kotlin.Function0)`) to only have recompositions when the derived value changes.

Please refer to the sample to learn how to use this API.

```kotlin
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.PagerState
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material3.Text
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

val pagerState = rememberPagerState { 10 }
Column(modifier = Modifier.fillMaxSize()) {
    HorizontalPager(modifier = Modifier.weight(0.9f), state = pagerState) { page ->
        Box(
            modifier =
                Modifier.padding(10.dp).background(Color.Blue).fillMaxWidth().aspectRatio(1f),
            contentAlignment = Alignment.Center,
        ) {
            Text(text = page.toString(), fontSize = 32.sp)
        }
    }
    Column(modifier = Modifier.weight(0.1f).fillMaxWidth()) {
        Text(text = "Current Page: ${pagerState.currentPage}")
        Text(text = "Current Page Offset Fraction: ${pagerState.currentPageOffsetFraction}")
        Text(text = "Target Page: ${pagerState.targetPage}")
        Text(text = "Settled Page Offset: ${pagerState.settledPage}")
    }
}
```

### interactionSource

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

```
val interactionSource: InteractionSource
```

`https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/InteractionSource` that will be used to dispatch drag events when this list is being dragged. If you want to know whether the fling (or animated scroll) is in progress, use `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#isScrollInProgress()`.

### isScrollInProgress

Cmn

```
open val isScrollInProgress: Boolean
```

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

### lastScrolledBackward

Cmn

```
open val lastScrolledBackward: Boolean
```

The value of this property is true under the following scenarios, otherwise it's false.

- This `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollableState` is currently scrolling backward.

- This `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollableState` was scrolling backward in its last scroll action.

### lastScrolledForward

Cmn

```
open val lastScrolledForward: Boolean
```

The value of this property is true under the following scenarios, otherwise it's false.

- This `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollableState` is currently scrolling forward.

- This `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollableState` was scrolling forward in its last scroll action.

### layoutInfo

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

```
val layoutInfo: PagerLayoutInfo
```

A `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerLayoutInfo` that contains useful information about the Pager's last layout pass. For instance, you can query which pages are currently visible in the layout.

This property is observable and is updated after every scroll or remeasure. If you use it in the composable function it will be recomposed on every change causing potential performance issues including infinity recomposition loop. Therefore, avoid using it in the composition.

If you want to run some side effects like sending an analytics event or updating a state based on this value consider using "snapshotFlow":

```kotlin
import androidx.compose.foundation.pager.PagerState
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.runtime.snapshotFlow

val pagerState = rememberPagerState() { 10 }
LaunchedEffect(pagerState) {
    snapshotFlow { pagerState.layoutInfo.visiblePagesInfo.firstOrNull() }
        .collect {
            // use the new first visible page info
        }
}
```

### pageCount

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

```
abstract val pageCount: Int
```

The total amount of pages present in this pager. The source of this data should be observable.

### scrollIndicatorState

Cmn

```
open val scrollIndicatorState: ScrollIndicatorState?
```

`https://developer.android.com/reference/kotlin/androidx/compose/foundation/ScrollIndicatorState` used for drawing a scroll indicator (e.g., a scrollbar).

This property may be `null` if scroll indicators are not applicable or if the underlying scrollable component does not support or provide this state.

### settledPage

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

```
val settledPage: Int
```

The page that is currently "settled". This is an animation/gesture unaware page in the sense that it will not be updated while the pages are being scrolled, but rather when the animation/scroll settles.

Please refer to the sample to learn how to use this API.

```kotlin
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.PagerState
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material3.Text
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

val pagerState = rememberPagerState { 10 }
Column(modifier = Modifier.fillMaxSize()) {
    HorizontalPager(modifier = Modifier.weight(0.9f), state = pagerState) { page ->
        Box(
            modifier =
                Modifier.padding(10.dp).background(Color.Blue).fillMaxWidth().aspectRatio(1f),
            contentAlignment = Alignment.Center,
        ) {
            Text(text = page.toString(), fontSize = 32.sp)
        }
    }
    Column(modifier = Modifier.weight(0.1f).fillMaxWidth()) {
        Text(text = "Current Page: ${pagerState.currentPage}")
        Text(text = "Current Page Offset Fraction: ${pagerState.currentPageOffsetFraction}")
        Text(text = "Target Page: ${pagerState.targetPage}")
        Text(text = "Settled Page Offset: ${pagerState.settledPage}")
    }
}
```

### targetPage

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

```
val targetPage: Int
```

The page this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/package-summary#Pager(androidx.compose.ui.Modifier,androidx.compose.foundation.pager.PagerState,androidx.compose.foundation.layout.PaddingValues,kotlin.Boolean,androidx.compose.foundation.gestures.Orientation,androidx.compose.foundation.gestures.TargetedFlingBehavior,kotlin.Boolean,androidx.compose.foundation.OverscrollEffect,kotlin.Int,androidx.compose.ui.unit.Dp,androidx.compose.foundation.pager.PageSize,androidx.compose.ui.input.nestedscroll.NestedScrollConnection,kotlin.Function1,androidx.compose.ui.Alignment.Horizontal,androidx.compose.ui.Alignment.Vertical,androidx.compose.foundation.gestures.snapping.SnapPosition,androidx.compose.foundation.gestures.BringIntoViewSpec,kotlin.Function2)` intends to settle to. During fling or animated scroll (from `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#animateScrollToPage(kotlin.Int,kotlin.Float,androidx.compose.animation.core.AnimationSpec)` this will represent the page this pager intends to settle to. When no scroll is ongoing, this will be equal to `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState#currentPage()`.

Please refer to the sample to learn how to use this API.

```kotlin
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.PagerState
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material3.Text
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

val pagerState = rememberPagerState { 10 }
Column(modifier = Modifier.fillMaxSize()) {
    HorizontalPager(modifier = Modifier.weight(0.9f), state = pagerState) { page ->
        Box(
            modifier =
                Modifier.padding(10.dp).background(Color.Blue).fillMaxWidth().aspectRatio(1f),
            contentAlignment = Alignment.Center,
        ) {
            Text(text = page.toString(), fontSize = 32.sp)
        }
    }
    Column(modifier = Modifier.weight(0.1f).fillMaxWidth()) {
        Text(text = "Current Page: ${pagerState.currentPage}")
        Text(text = "Current Page Offset Fraction: ${pagerState.currentPageOffsetFraction}")
        Text(text = "Target Page: ${pagerState.targetPage}")
        Text(text = "Settled Page Offset: ${pagerState.settledPage}")
    }
}
```