Class

PagerState

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

Source set: Android
public class PagerState(
    @IntRange(from = 0) currentPage: Int = 0,
    @FloatRange(from = -0.5, to = 0.5) currentPageOffsetFraction: Float = 0f,
    @IntRange(from = 1) pageCount: () -> Int,
) : ScrollableState

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

Parameters

currentPage The index of the current active page.
currentPageOffsetFraction 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 The number of pages in this Pager.

Properties

currentPage

Source set: Android
public val currentPage: Int

The current page displayed by the pager.

currentPageOffsetFraction

Source set: Android
public val currentPageOffsetFraction: 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

pageCount

Source set: Android
public val pageCount: Int

The total number of pages present in this pager.

settledPage

Source set: Android
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
public val targetPage: Int

The page this pager intends to settle to. During fling or animated scroll (from animateScrollToPage) this will represent the page this pager intends to settle to. When no scroll is ongoing, this will be equal to currentPage.

layoutInfo

Source set: Android
public val layoutInfo: PagerLayoutInfo

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

interactionSource

Source set: Android
public val interactionSource: InteractionSource

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.

Functions

scrollToPage

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

Scroll (jump immediately) to a given page.

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.

animateScrollToPage

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

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 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.
animationSpec An AnimationSpec to move between pages. We'll use a spring as the default animation.

Companion Object

Properties

Source set: Android
public val Saver: Saver<PagerState, *>

To keep current page and page offset saved

Last updated: