{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

PagerDefaults

@ExperimentalFoundationApi
public static class PagerDefaults


Contains the default values used by Pager.

Summary

Public fields

static @NonNull PagerDefaults

Public methods

final @NonNull SnapFlingBehavior
@Composable
flingBehavior(
    @NonNull PagerState state,
    @NonNull PagerSnapDistance pagerSnapDistance,
    @NonNull AnimationSpec<@NonNull Float> lowVelocityAnimationSpec,
    @NonNull DecayAnimationSpec<@NonNull Float> highVelocityAnimationSpec,
    @NonNull AnimationSpec<@NonNull Float> snapAnimationSpec,
    @NonNull Dp snapVelocityThreshold,
    float snapPositionalThreshold
)

A SnapFlingBehavior that will snap pages to the start of the layout.

final @NonNull NestedScrollConnection

The default implementation of Pager's pageNestedScrollConnection.

Public fields

INSTANCE

public static @NonNull PagerDefaults INSTANCE

Public methods

flingBehavior

@Composable
public final @NonNull SnapFlingBehavior flingBehavior(
    @NonNull PagerState state,
    @NonNull PagerSnapDistance pagerSnapDistance,
    @NonNull AnimationSpec<@NonNull Float> lowVelocityAnimationSpec,
    @NonNull DecayAnimationSpec<@NonNull Float> highVelocityAnimationSpec,
    @NonNull AnimationSpec<@NonNull Float> snapAnimationSpec,
    @NonNull Dp snapVelocityThreshold,
    float snapPositionalThreshold
)

A SnapFlingBehavior that will snap pages to the start of the layout. One can use the given parameters to control how the snapping animation will happen.

Parameters
@NonNull PagerState state

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

@NonNull PagerSnapDistance pagerSnapDistance

A way to control the snapping destination for this Pager. The default behavior will result in any fling going to the next page in the direction of the fling (if the fling has enough velocity, otherwise we'll bounce back). Use PagerSnapDistance.atMost to define a maximum number of pages this Pager is allowed to fling after scrolling is finished and fling has started.

@NonNull AnimationSpec<@NonNull Float> lowVelocityAnimationSpec

The animation spec used to approach the target offset. When the fling velocity is not large enough. Large enough means large enough to naturally decay.

@NonNull DecayAnimationSpec<@NonNull Float> highVelocityAnimationSpec

The animation spec used to approach the target offset. When the fling velocity is large enough. Large enough means large enough to naturally decay.

@NonNull AnimationSpec<@NonNull Float> snapAnimationSpec

The animation spec used to finally snap to the position.

@NonNull Dp snapVelocityThreshold

The minimum velocity required for a fling to be considered high enough to make pages animate through lowVelocityAnimationSpec and highVelocityAnimationSpec.

float snapPositionalThreshold

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 we consider 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 we scroll more than 35% of the page size, then will jump to the next page, if not we scroll back. The default value is 50% meaning if we scroll the page more than 50% and let go it will snap to the next page. Note that any fling that has high enough velocity will always move to the next page in the direction of the fling.

Returns
@NonNull SnapFlingBehavior

An instance of FlingBehavior that will perform Snapping to the next page by default. The animation will be governed by the post scroll velocity and we'll use either lowVelocityAnimationSpec or highVelocityAnimationSpec to approach the snapped position and the last step of the animation will be performed by snapAnimationSpec. If a velocity is not high enough (lower than snapVelocityThreshold) the pager will use snapAnimationSpec to reach the snapped position. If the velocity is high enough, we'll use the logic described in highVelocityAnimationSpec and lowVelocityAnimationSpec.

See also
SnapFlingBehavior

for more information on what which parameter controls in the overall snapping animation.

pageNestedScrollConnection

public final @NonNull NestedScrollConnection pageNestedScrollConnection(@NonNull Orientation orientation)

The default implementation of Pager's pageNestedScrollConnection. All fling scroll deltas will be consumed by the Pager.

Parameters
@NonNull Orientation orientation

The orientation of the pager. This will be used to determine which direction it will consume everything. The other direction will not be consumed.