object PagerDefaults


Contains the default values used by Pager. These are optimised for Wear.

Summary

Constants

const Int

The default value of beyondViewportPageCount used to specify the number of pages to compose and layout before and after the visible pages.

const Float
Stiffness = 2000.0f

The recommended medium-high stiffness used by default for the spring stiffness parameter in the Pager's snap animation

const Float

The default value of swipeToDismissEdgeZoneFraction used to configure the size of the edge zone in a HorizontalPager.

Public functions

TargetedFlingBehavior
@Composable
snapFlingBehavior(
    state: PagerState,
    pagerSnapDistance: PagerSnapDistance,
    decayAnimationSpec: DecayAnimationSpec<Float>,
    snapAnimationSpec: AnimationSpec<Float>,
    snapPositionalThreshold: @FloatRange(from = 0.0, to = 1.0) Float
)

Default fling behavior for pagers on Wear, snaps at most one page at a time.

Constants

BeyondViewportPageCount

Added in 1.5.0-alpha07
const val BeyondViewportPageCount = 0: Int

The default value of beyondViewportPageCount used to specify the number of pages to compose and layout before and after the visible pages. It does not include the pages automatically composed and laid out by the pre-fetcher in the direction of the scroll during scroll events.

Stiffness

Added in 1.5.0-alpha07
const val Stiffness = 2000.0f: Float

The recommended medium-high stiffness used by default for the spring stiffness parameter in the Pager's snap animation

SwipeToDismissEdgeZoneFraction

Added in 1.5.0-alpha07
const val SwipeToDismissEdgeZoneFraction = 0.15f: Float

The default value of swipeToDismissEdgeZoneFraction used to configure the size of the edge zone in a HorizontalPager.

Public functions

snapFlingBehavior

Added in 1.5.0-alpha07
@Composable
fun snapFlingBehavior(
    state: PagerState,
    pagerSnapDistance: PagerSnapDistance = PagerSnapDistance.atMost(1),
    decayAnimationSpec: DecayAnimationSpec<Float> = rememberSplineBasedDecay(),
    snapAnimationSpec: AnimationSpec<Float> = spring(Spring.DampingRatioNoBouncy, PagerDefaults.Stiffness),
    snapPositionalThreshold: @FloatRange(from = 0.0, to = 1.0) Float = 0.5f
): TargetedFlingBehavior

Default fling behavior for pagers on Wear, snaps at most one page at a time.

Parameters
state: PagerState

The PagerState that controls the Pager to which this FlingBehavior will be applied to.

pagerSnapDistance: PagerSnapDistance = PagerSnapDistance.atMost(1)

A way to control the snapping destination for this Pager. Use PagerSnapDistance.atMost to define a maximum number of pages this Pager is allowed to fling after scrolling is finished and fling has started.

decayAnimationSpec: DecayAnimationSpec<Float> = rememberSplineBasedDecay()

The animation spec used to approach the target offset. When the fling velocity is large enough. Large enough means large enough to naturally decay. For single page snapping this usually never happens since there won't be enough space to run a decay animation.

snapAnimationSpec: AnimationSpec<Float> = spring(Spring.DampingRatioNoBouncy, PagerDefaults.Stiffness)

The animation spec used to finally snap to the position. This animation will be often used in 2 cases: 1) There was enough space to an approach animation, the Pager will use snapAnimationSpec in the last step of the animation to settle the page into position. 2) There was not enough space to run the approach animation. By default a Spring animation with no bounciness and high stiffness is used to ensure the Pager settles quickly so that contents are focused and clickable.

snapPositionalThreshold: @FloatRange(from = 0.0, to = 1.0) Float = 0.5f

If the fling has a low velocity (e.g. slow scroll), this fling behavior will use this snap threshold in order to determine if the pager should snap back or move forward. Use a number between 0 and 1 as a fraction of the page size that needs to be scrolled before the Pager considers it should move to the next page. For instance, if snapPositionalThreshold = 0.35, it means if this pager is scrolled with a slow velocity and the Pager scrolls more than 35% of the page size, then will jump to the next page, if not it scrolls back. Note that any fling that has high enough velocity will always move to the next page in the direction of the fling.