# GlimmerPagerState

Artifact: [androidx.xr.glimmer:glimmer](https://developer.android.com/jetpack/androidx/releases/xr-glimmer) [View Source](https://cs.android.com/search?q=file:androidx/xr/glimmer/pager/GlimmerPagerState.kt+class:androidx.xr.glimmer.pager.GlimmerPagerState) Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)


```
class GlimmerPagerState : ScrollableState
```

<br />

*** ** * ** ***

The state that can be used to control `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerHorizontalPager.composable#GlimmerHorizontalPager(androidx.xr.glimmer.pager.GlimmerPagerState,androidx.compose.ui.Modifier,androidx.compose.foundation.layout.PaddingValues,kotlin.Int,androidx.compose.ui.unit.Dp,androidx.compose.ui.Alignment.Vertical,kotlin.Boolean,kotlin.Boolean,kotlin.Function1,kotlin.Function0,kotlin.Function2)`.

## Summary

| ### Public companion properties |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/saveable/Saver<https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState, *>` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#Saver()` The default `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#Saver()` implementation for `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState`. |

| ### Public constructors |
|---|
| `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/annotation/RememberInComposition https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#GlimmerPagerState(kotlin.Int,kotlin.Float,kotlin.Function0)( currentPage: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) 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, pageCount: () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` |

| ### Public functions |
|---|---|
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#animateScrollToPage(kotlin.Int,kotlin.Float,androidx.compose.animation.core.AnimationSpec)( 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, animationSpec: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationSpec<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html> )` Scroll to the given `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#animateScrollToPage(kotlin.Int,kotlin.Float,androidx.compose.animation.core.AnimationSpec)` with an animation. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#dispatchRawDelta(kotlin.Float)(delta: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#getOffsetDistanceInPages(kotlin.Int)(page: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` A utility function to help to calculate a given page's offset. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#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/xr/glimmer/pager/GlimmerPagerState#requestScrollToPage(kotlin.Int,kotlin.Float)` to be at the snapped position during the next remeasure, offset by `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#requestScrollToPage(kotlin.Int,kotlin.Float)`, and schedules a remeasure. |
| `open suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#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)` |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#scrollToPage(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 )` Scroll immediately to the given `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#scrollToPage(kotlin.Int,kotlin.Float)`, without animating. |
| `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/xr/glimmer/pager/GlimmerPagerState#(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/xr/glimmer/pager/GlimmerPagerState#(androidx.compose.foundation.gestures.ScrollScope).updateCurrentPage(kotlin.Int,kotlin.Float)` with a given `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#(androidx.compose.foundation.gestures.ScrollScope).updateCurrentPage(kotlin.Int,kotlin.Float)` inside a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollScope`. |
| `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/xr/glimmer/pager/GlimmerPagerState#(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/xr/glimmer/pager/GlimmerPagerState#(androidx.compose.foundation.gestures.ScrollScope).updateTargetPage(kotlin.Int)` during a programmatic scroll operation. |

| ### Public properties |
|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#canScrollBackward()` Whether this pager can scroll backward (is not at the first page). |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#canScrollForward()` Whether this pager can scroll forward (has more pages to show). |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#currentPage()` The page that sits closest to the snapped position. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#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). |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/InteractionSource` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#interactionSource()` `https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/InteractionSource` that will be used to dispatch drag events when this pager is being dragged. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#isScrollInProgress()` Whether this pager is currently scrolling by gesture, fling or animation. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#lastScrolledBackward()` Whether the last scroll action was in the backward direction. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#lastScrolledForward()` Whether the last scroll action was in the forward direction. |
| `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerLayoutInfo` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#layoutInfo()` A `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerLayoutInfo` that contains information about the Pager's last layout pass. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#pageCount()` The total amount of pages present in this pager. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#settledPage()` The page that is currently "settled". |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#targetPage()` The page that is currently being scrolled towards. |

### Inherited properties

From [androidx.compose.foundation.gestures.ScrollableState](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollableState) `open https://developer.android.com/reference/kotlin/androidx/compose/foundation/ScrollIndicatorState?` `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollableState#scrollIndicatorState()`

## Public companion properties

### Saver

Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

```
val Saver: Saver<GlimmerPagerState, *>
```

The default `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#Saver()` implementation for `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState`.

## Public constructors

### GlimmerPagerState

Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

```
@RememberInComposition
GlimmerPagerState(
    currentPage: @IntRange(from = 0) Int = 0,
    currentPageOffsetFraction: @FloatRange(from = -0.5, to = 0.5) Float = 0.0f,
    pageCount: () -> Int
)
```

| Parameters |
|---|---|
| `currentPage: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = 0` | The index of the page to show initially. Must be non-negative. Defaults to 0. |
| `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 as a fraction of the page size. This should vary between -0.5 and 0.5 and indicates how to offset the initial page from the snapped position. |
| `pageCount: () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | A lambda returning the total number of pages in the pager. |

## Public functions

### animateScrollToPage

Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

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

Scroll to the given `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#animateScrollToPage(kotlin.Int,kotlin.Float,androidx.compose.animation.core.AnimationSpec)` with an animation.

```kotlin
import androidx.compose.animation.core.animate
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextMotion
import androidx.xr.glimmer.Button
import androidx.xr.glimmer.Card
import androidx.xr.glimmer.LocalTextStyle
import androidx.xr.glimmer.Text
import androidx.xr.glimmer.pager.GlimmerHorizontalPager
import androidx.xr.glimmer.pager.GlimmerPagerState
import androidx.xr.glimmer.pager.rememberGlimmerPagerState

val state = rememberGlimmerPagerState(initialPage = 5, pageCount = { 10 })
val scope = rememberCoroutineScope()
Column {
    Button(onClick = { scope.launch { state.animateScrollToPage(1) } }) {
        Text(text = "Scroll to Page 1")
    }

    GlimmerHorizontalPager(modifier = Modifier.fillMaxSize(), state = state) { page ->
        Card {
            Text(
                text = "Page: $page",
                style = LocalTextStyle.current.copy(textMotion = TextMotion.Animated),
            )
        }
    }
}
```

| 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 of the 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 determines how far the destination page shifts 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()` | the `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationSpec` to be used for the scroll animation. |

### dispatchRawDelta

Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

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

### getOffsetDistanceInPages

Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

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

A 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/xr/glimmer/pager/GlimmerPagerState#getOffsetDistanceInPages(kotlin.Int)` is from the settled position (represented by `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#currentPage()` offset). The difference here is that `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#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/xr/glimmer/pager/GlimmerPagerState#getOffsetDistanceInPages(kotlin.Int)` is different than `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#currentPage()`.

For instance, if currentPage=0 and we call `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#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/xr/glimmer/pager/GlimmerPagerState#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/xr/glimmer/pager/GlimmerPagerState#currentPageOffsetFraction()`, so if `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#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/xr/glimmer/pager/GlimmerPagerState#pageCount()`. |

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

### requestScrollToPage

Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

```
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/xr/glimmer/pager/GlimmerPagerState#requestScrollToPage(kotlin.Int,kotlin.Float)` to be at the snapped position during the next remeasure, offset by `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#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` | A fraction of the page size that determines how far the destination page shifts from its snapped position. |

### scroll

Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

```
open suspend fun scroll(scrollPriority: MutatePriority, block: suspend ScrollScope.() -> Unit): Unit
```

### scrollToPage

Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

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

Scroll immediately to the given `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#scrollToPage(kotlin.Int,kotlin.Float)`, without animating.

```kotlin
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextMotion
import androidx.xr.glimmer.Button
import androidx.xr.glimmer.Card
import androidx.xr.glimmer.LocalTextStyle
import androidx.xr.glimmer.Text
import androidx.xr.glimmer.pager.GlimmerHorizontalPager
import androidx.xr.glimmer.pager.GlimmerPagerState
import androidx.xr.glimmer.pager.rememberGlimmerPagerState

val state = rememberGlimmerPagerState(initialPage = 5, pageCount = { 10 })
val scope = rememberCoroutineScope()
Column {
    Button(onClick = { scope.launch { state.scrollToPage(1) } }) {
        Text(text = "Scroll to Page 1")
    }

    GlimmerHorizontalPager(modifier = Modifier.fillMaxSize(), state = state) { page ->
        Card {
            Text(
                text = "Page: $page",
                style = LocalTextStyle.current.copy(textMotion = TextMotion.Animated),
            )
        }
    }
}
```

| 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 of the 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 determines how far the destination page shifts from its snapped position. |

### ScrollScope.updateCurrentPage

Artifact: [androidx.xr.glimmer:glimmer](https://developer.android.com/jetpack/androidx/releases/xr-glimmer) [View Source](https://cs.android.com/search?q=file:androidx/xr/glimmer/pager/GlimmerPagerState.kt+function:updateCurrentPage) Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

```
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/xr/glimmer/pager/GlimmerPagerState#(androidx.compose.foundation.gestures.ScrollScope).updateCurrentPage(kotlin.Int,kotlin.Float)` with a given `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#(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/xr/glimmer/pager/GlimmerPagerState#currentPage()` and `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#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/xr/glimmer/pager/GlimmerPagerState#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.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextMotion
import androidx.xr.glimmer.Button
import androidx.xr.glimmer.Card
import androidx.xr.glimmer.LocalTextStyle
import androidx.xr.glimmer.Text
import androidx.xr.glimmer.pager.GlimmerHorizontalPager
import androidx.xr.glimmer.pager.GlimmerPagerState
import androidx.xr.glimmer.pager.rememberGlimmerPagerState

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

        // pre-jump to 1 page before our target page
        updateCurrentPage(preJumpPosition, pageOffsetFraction = 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 = rememberGlimmerPagerState(initialPage = 5, pageCount = { 10 })
val scope = rememberCoroutineScope()

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

    GlimmerHorizontalPager(modifier = Modifier.fillMaxSize(), state = state) { page ->
        Card {
            Text(
                text = "Page: $page",
                style = LocalTextStyle.current.copy(textMotion = TextMotion.Animated),
            )
        }
    }
}
```

| 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 determines how far the destination page shifts from its snapped position. |

### ScrollScope.updateTargetPage

Artifact: [androidx.xr.glimmer:glimmer](https://developer.android.com/jetpack/androidx/releases/xr-glimmer) [View Source](https://cs.android.com/search?q=file:androidx/xr/glimmer/pager/GlimmerPagerState.kt+function:updateTargetPage) Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

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

Used to update `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#(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/xr/glimmer/pager/GlimmerPagerState#scroll(androidx.compose.foundation.MutatePriority,kotlin.coroutines.SuspendFunction1)`) is executed in order to correctly update `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#(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/xr/glimmer/pager/GlimmerPagerState#(androidx.compose.foundation.gestures.ScrollScope).updateTargetPage(kotlin.Int)`. By the end of the `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#scroll(androidx.compose.foundation.MutatePriority,kotlin.coroutines.SuspendFunction1)` block, when the `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerHorizontalPager.composable#GlimmerHorizontalPager(androidx.xr.glimmer.pager.GlimmerPagerState,androidx.compose.ui.Modifier,androidx.compose.foundation.layout.PaddingValues,kotlin.Int,androidx.compose.ui.unit.Dp,androidx.compose.ui.Alignment.Vertical,kotlin.Boolean,kotlin.Boolean,kotlin.Function1,kotlin.Function0,kotlin.Function2)` is no longer scrolling `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#(androidx.compose.foundation.gestures.ScrollScope).updateTargetPage(kotlin.Int)` will assume the value of `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerState#currentPage()`.

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

```kotlin
import androidx.compose.animation.core.animate
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextMotion
import androidx.xr.glimmer.Button
import androidx.xr.glimmer.Card
import androidx.xr.glimmer.LocalTextStyle
import androidx.xr.glimmer.Text
import androidx.xr.glimmer.pager.GlimmerHorizontalPager
import androidx.xr.glimmer.pager.GlimmerPagerState
import androidx.xr.glimmer.pager.rememberGlimmerPagerState

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

        // pre-jump to 1 page before our target page
        updateCurrentPage(preJumpPosition, pageOffsetFraction = 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 = rememberGlimmerPagerState(initialPage = 5, pageCount = { 10 })
val scope = rememberCoroutineScope()

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

    GlimmerHorizontalPager(modifier = Modifier.fillMaxSize(), state = state) { page ->
        Card {
            Text(
                text = "Page: $page",
                style = LocalTextStyle.current.copy(textMotion = TextMotion.Animated),
            )
        }
    }
}
```

## Public properties

### canScrollBackward

```
open val canScrollBackward: Boolean
```

Whether this pager can scroll backward (is not at the first page).

### canScrollForward

```
open val canScrollForward: Boolean
```

Whether this pager can scroll forward (has more pages to show).

### currentPage

Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

```
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.

### currentPageOffsetFraction

Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

```
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/xr/glimmer/pager/GlimmerPagerState#currentPage()` is in the snapped position. The value will flip once the current page changes.

### interactionSource

Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

```
val interactionSource: InteractionSource
```

`https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/InteractionSource` that will be used to dispatch drag events when this pager 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/xr/glimmer/pager/GlimmerPagerState#isScrollInProgress()`.

### isScrollInProgress

Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

```
open val isScrollInProgress: Boolean
```

Whether this pager is currently scrolling by gesture, fling or animation.

### lastScrolledBackward

```
open val lastScrolledBackward: Boolean
```

Whether the last scroll action was in the backward direction.

### lastScrolledForward

```
open val lastScrolledForward: Boolean
```

Whether the last scroll action was in the forward direction.

### layoutInfo

Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

```
val layoutInfo: GlimmerPagerLayoutInfo
```

A `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/pager/GlimmerPagerLayoutInfo` that contains information about the Pager's last layout pass.

### pageCount

Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

```
val pageCount: Int
```

The total amount of pages present in this pager.

### settledPage

Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

```
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.

### targetPage

Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

```
val targetPage: Int
```

The page that is currently being scrolled towards. This is an observable value and will change as the pager scrolls either by gesture or animation.