---
title: "GlimmerPagerState"
description: "The state that can be used to control GlimmerHorizontalPager."
type: "class"
lastmod: "2026-05-08T01:17:00.902039Z"
---
## API Reference

> Source set: Android

```kotlin
public class GlimmerPagerState
@RememberInComposition
constructor(
    @IntRange(from = 0) currentPage: Int = 0,
    @FloatRange(from = -0.5, to = 0.5) currentPageOffsetFraction: Float = 0f,
    pageCount: () -> Int,
) : ScrollableState
```

The state that can be used to control [GlimmerHorizontalPager](/jetpack-compose/androidx.xr.glimmer/glimmer/components/GlimmerHorizontalPager).

#### Parameters

| | |
| --- | --- |
| currentPage | The index of the page to show initially. Must be non-negative. Defaults to 0. |
| currentPageOffsetFraction | 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 | A lambda returning the total number of pages in the pager. |

## Properties

### pageCount

> Source set: Android

```kotlin
public val pageCount: Int
```

The total amount of pages present in this pager.

### layoutInfo

> Source set: Android

```kotlin
public val layoutInfo: GlimmerPagerLayoutInfo
```

A [GlimmerPagerLayoutInfo](/jetpack-compose/androidx.xr.glimmer/glimmer/interfaces/GlimmerPagerLayoutInfo) that contains information about the Pager's last layout pass.

### interactionSource

> Source set: Android

```kotlin
public val interactionSource: InteractionSource
```

[InteractionSource](/jetpack-compose/androidx.compose.foundation/foundation/interfaces/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
`isScrollInProgress`.

### currentPage

> Source set: Android

```kotlin
public 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

> Source set: Android

```kotlin
public 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 [currentPage](#currentpage) is in the snapped position. The value will flip
once the current page changes.

### settledPage

> Source set: Android

```kotlin
public 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

> Source set: Android

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

## Functions

### updateCurrentPage

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

Jump immediately to a given `page` with a given `pageOffsetFraction` inside a [ScrollScope](/jetpack-compose/androidx.compose.foundation/foundation/interfaces/ScrollScope).
Use this method to create custom animated scrolling experiences. This will update the value
of [currentPage](#currentpage) and [currentPageOffsetFraction](#currentpageoffsetfraction) immediately, but can only be used inside a
[ScrollScope](/jetpack-compose/androidx.compose.foundation/foundation/interfaces/ScrollScope), use `scroll` to gain access to a [ScrollScope](/jetpack-compose/androidx.compose.foundation/foundation/interfaces/ScrollScope).

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

#### Parameters

| | |
| --- | --- |
| page | The destination page to scroll to |
| pageOffsetFraction | A fraction of the page size that indicates the offset the destination page will be offset from its snapped position. |

### updateTargetPage

```kotlin
public fun ScrollScope.updateTargetPage(targetPage: Int)
```

Used to update [targetPage](#targetpage) during a programmatic scroll operation. This can only be called
inside a [ScrollScope](/jetpack-compose/androidx.compose.foundation/foundation/interfaces/ScrollScope) and should be called anytime a custom scroll (through `scroll`) is
executed in order to correctly update [targetPage](#targetpage). This will not move the pages and it's
still the responsibility of the caller to call [ScrollScope.scrollBy](/jetpack-compose/androidx.compose.foundation/foundation/interfaces/ScrollScope) in order to actually
get to [targetPage](#targetpage). By the end of the `scroll` block, when the [GlimmerHorizontalPager](/jetpack-compose/androidx.xr.glimmer/glimmer/components/GlimmerHorizontalPager) is
no longer scrolling [targetPage](#targetpage) will assume the value of [currentPage](#currentpage).

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

### requestScrollToPage

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

Requests the `page` to be at the snapped position during the next remeasure, offset by
`pageOffsetFraction`, 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 | the index to which to scroll. Must be non-negative. |
| pageOffsetFraction | the offset fraction that the page should end up after the scroll. |

### scrollToPage

```kotlin
public suspend fun scrollToPage(page: Int)
```

Scroll immediately to the given `page`, without animating.

#### Parameters

| | |
| --- | --- |
| page | the index of the page to scroll to. |

### animateScrollToPage

```kotlin
public suspend fun animateScrollToPage(
        page: Int,
        animationSpec: AnimationSpec<Float> = spring(),
    )
```

Scroll to the given `page` with an animation.

#### Parameters

| | |
| --- | --- |
| page | the index of the page to scroll to. |
| animationSpec | the [AnimationSpec](/jetpack-compose/androidx.compose.animation/animation-core/interfaces/AnimationSpec) to be used for the scroll animation. |

### getOffsetDistanceInPages

```kotlin
public 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 `page` is from the settled position (represented by [currentPage](#currentpage) offset).
The difference here is that [currentPageOffsetFraction](#currentpageoffsetfraction) is a value between -0.5 and 0.5 and
the value calculated by this function can be larger than these numbers if `page` is different
than [currentPage](#currentpage).

For instance, if currentPage=0 and we call [getOffsetDistanceInPages](#getoffsetdistanceinpages) 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 [getOffsetDistanceInPages](#getoffsetdistanceinpages) 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 [currentPageOffsetFraction](#currentpageoffsetfraction), so if [currentPage](#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 | The page to calculate the offset from. This should be between 0 and [pageCount](#pagecount). |

#### Returns

| | |
| --- | --- |
|  | The offset of `page` with respect to [currentPage](#currentpage). |

## Companion Object

#### Properties

> Source set: Android

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

The default [Saver](/jetpack-compose/androidx.compose.runtime/runtime-saveable/interfaces/Saver) implementation for [GlimmerPagerState](/jetpack-compose/androidx.xr.glimmer/glimmer/classes/GlimmerPagerState).
