Class

PagerState

The state that can be used to control VerticalPager and HorizontalPager

Source set: Common
public abstract class PagerState internal constructor(
    currentPage: Int = 0,
    @FloatRange(from = -0.5, to = 0.5) currentPageOffsetFraction: Float = 0f,
    prefetchScheduler: PrefetchScheduler? = null,
) : ScrollableState

The state that can be used to control VerticalPager and HorizontalPager

Properties

pageCount

Source set: Common
public abstract val pageCount: Int

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

layoutInfo

Source set: Common
public val layoutInfo: PagerLayoutInfo

A 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":

interactionSource

Source set: Common
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.

currentPage

Source set: Common
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.

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

settledPage

Source set: Common
public val settledPage: Int {
        if (isScrollInProgress) {
            settledPageState

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.

Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: