class PagerState : ScrollableState


The state that can be used in conjunction with Wear HorizontalPager and VerticalPager.

Summary

Public companion properties

Saver<PagerState, *>

To keep current page and page offset saved

Public constructors

PagerState(
    currentPage: @IntRange(from = 0) Int,
    currentPageOffsetFraction: @FloatRange(from = -0.5, to = 0.5) Float,
    pageCount: @IntRange(from = 1) () -> Int
)

Public functions

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

Scroll animate to a given page.

open Float
open suspend Unit
scroll(scrollPriority: MutatePriority, block: suspend ScrollScope.() -> Unit)
suspend Unit
scrollToPage(
    page: Int,
    pageOffsetFraction: @FloatRange(from = -0.5, to = 0.5) Float
)

Scroll (jump immediately) to a given page.

Public properties

Int

The current page displayed by the pager.

Float

The fractional offset from the start of the current page, in the range -0.5,0.5, where 0 indicates the start of the current page

InteractionSource

InteractionSource that will be used to dispatch drag events when this list is being dragged.

open Boolean
PagerLayoutInfo

A PagerLayoutInfo that contains useful information about the Pager's last layout pass.

Int

The total number of pages present in this pager.

Int

The page that is currently "settled".

Public companion properties

Saver

Added in 1.5.0-alpha11
val SaverSaver<PagerState, *>

To keep current page and page offset saved

Public constructors

PagerState

Added in 1.5.0-alpha11
PagerState(
    currentPage: @IntRange(from = 0) Int = 0,
    currentPageOffsetFraction: @FloatRange(from = -0.5, to = 0.5) Float = 0.0f,
    pageCount: @IntRange(from = 1) () -> Int
)
Parameters
currentPage: @IntRange(from = 0) Int = 0

The index of the current active page.

currentPageOffsetFraction: @FloatRange(from = -0.5, to = 0.5) Float = 0.0f

The fractional offset from the start of the current page. Should be between -0.5 and 0.5, where 0 indicates the start of the initial page.

pageCount: @IntRange(from = 1) () -> Int

The number of pages in this Pager.

Public functions

animateScrollToPage

Added in 1.5.0-alpha11
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 page. If the page is too far away from 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 page.

Parameters
page: Int

The destination page to scroll to

pageOffsetFraction: @FloatRange(from = -0.5, to = 0.5) Float = 0.0f

A fraction of the page size that indicates the offset the destination page will be offset from its snapped position.

animationSpec: AnimationSpec<Float> = spring()

An AnimationSpec to move between pages. We'll use a spring as the default animation.

dispatchRawDelta

Added in 1.5.0-alpha11
open fun dispatchRawDelta(delta: Float): Float

scroll

Added in 1.5.0-alpha11
open suspend fun scroll(scrollPriority: MutatePriority, block: suspend ScrollScope.() -> Unit): Unit

scrollToPage

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

Scroll (jump immediately) to a given page.

Parameters
page: Int

The destination page to scroll to

pageOffsetFraction: @FloatRange(from = -0.5, to = 0.5) Float = 0.0f

A fraction of the page size that indicates the offset the destination page will be offset from its snapped position.

Public properties

currentPage

Added in 1.5.0-alpha11
val currentPageInt

The current page displayed by the pager.

currentPageOffsetFraction

Added in 1.5.0-alpha11
val currentPageOffsetFractionFloat

The fractional offset from the start of the current page, in the range -0.5,0.5, where 0 indicates the start of the current page

interactionSource

Added in 1.5.0-alpha11
val interactionSourceInteractionSource

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

isScrollInProgress

Added in 1.5.0-alpha11
open val isScrollInProgressBoolean

layoutInfo

Added in 1.5.0-alpha11
val layoutInfoPagerLayoutInfo

A PagerLayoutInfo that contains useful information about the Pager's last layout pass. For instance, you can query the page size.

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

pageCount

Added in 1.5.0-alpha11
val pageCountInt

The total number of pages present in this pager.

settledPage

Added in 1.5.0-alpha11
val settledPageInt

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.