PagerState
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( |
Public functions |
|
|---|---|
suspend Unit |
animateScrollToPage(Scroll animate to a given |
open Float |
dispatchRawDelta(delta: Float) |
open suspend Unit |
scroll(scrollPriority: MutatePriority, block: suspend ScrollScope.() -> Unit) |
suspend Unit |
scrollToPage(Scroll (jump immediately) to a given |
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 |
|
open Boolean |
|
PagerLayoutInfo |
A |
Int |
The total number of pages present in this pager. |
Int |
The page that is currently "settled". |
Int |
The page this pager intends to settle to. |
Inherited properties |
||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
Public companion properties
Public constructors
PagerState
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
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 |
scroll
open suspend fun scroll(scrollPriority: MutatePriority, block: suspend ScrollScope.() -> Unit): Unit
scrollToPage
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
currentPageOffsetFraction
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
interactionSource
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.
layoutInfo
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".
settledPage
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
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.