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

PagerSnapDistance

@ExperimentalFoundationApi
public interface PagerSnapDistance


PagerSnapDistance defines the way the Pager will treat the distance between the current page and the page where it will settle.

Summary

Nested types

public static class PagerSnapDistance.Companion

Public methods

abstract int
calculateTargetPage(
    int startPage,
    int suggestedTargetPage,
    float velocity,
    int pageSize,
    int pageSpacing
)

Provides a chance to change where the Pager fling will settle.

Public methods

calculateTargetPage

abstract int calculateTargetPage(
    int startPage,
    int suggestedTargetPage,
    float velocity,
    int pageSize,
    int pageSpacing
)

Provides a chance to change where the Pager fling will settle.

Parameters
int startPage

The current page right before the fling starts.

int suggestedTargetPage

The proposed target page where this fling will stop. This target will be the page that will be correctly positioned (snapped) after naturally decaying with velocity using a DecayAnimationSpec.

float velocity

The initial fling velocity.

int pageSize

The page size for this Pager.

int pageSpacing

The spacing used between pages.

Returns
int

An updated target page where to settle. Note that this value needs to be between 0 and the total count of pages in this pager. If an invalid value is passed, the pager will coerce within the valid values.