# PagerDefaults

Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/pager/Pager.kt+class:androidx.compose.foundation.pager.PagerDefaults) Added in [1.4.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.4.0) Common/All
- Cmn

  ```
  object PagerDefaults
  ```

*** ** * ** ***

Contains the default values used by `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/package-summary#Pager(androidx.compose.ui.Modifier,androidx.compose.foundation.pager.PagerState,androidx.compose.foundation.layout.PaddingValues,kotlin.Boolean,androidx.compose.foundation.gestures.Orientation,androidx.compose.foundation.gestures.TargetedFlingBehavior,kotlin.Boolean,androidx.compose.foundation.OverscrollEffect,kotlin.Int,androidx.compose.ui.unit.Dp,androidx.compose.foundation.pager.PageSize,androidx.compose.ui.input.nestedscroll.NestedScrollConnection,kotlin.Function1,androidx.compose.ui.Alignment.Horizontal,androidx.compose.ui.Alignment.Vertical,androidx.compose.foundation.gestures.snapping.SnapPosition,androidx.compose.foundation.gestures.BringIntoViewSpec,kotlin.Function2)`.

## Summary

| ### Constants |
|---|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerDefaults#BeyondViewportPageCount() = 0` The default value of beyondViewportPageCount used to specify the number of pages to compose and layout before and after the visible pages. | Cmn |

| ### Public functions |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/BringIntoViewSpec` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerDefaults#bringIntoViewSpec(androidx.compose.foundation.pager.PagerState)(state: https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState)` Pager's default `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/BringIntoViewSpec` that settles bring into view requests in accordance with the pager's snapping logic. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/TargetedFlingBehavior` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerDefaults#flingBehavior(androidx.compose.foundation.pager.PagerState,androidx.compose.foundation.pager.PagerSnapDistance,androidx.compose.animation.core.DecayAnimationSpec,androidx.compose.animation.core.AnimationSpec,kotlin.Float)( state: https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState, pagerSnapDistance: https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerSnapDistance, decayAnimationSpec: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DecayAnimationSpec<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>, snapAnimationSpec: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationSpec<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>, snapPositionalThreshold: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html )` A `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/snapping/package-summary#snapFlingBehavior(androidx.compose.foundation.gestures.snapping.SnapLayoutInfoProvider,androidx.compose.animation.core.DecayAnimationSpec,androidx.compose.animation.core.AnimationSpec)` that will snap pages to the start of the layout. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/nestedscroll/NestedScrollConnection` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerDefaults#pageNestedScrollConnection(androidx.compose.foundation.pager.PagerState,androidx.compose.foundation.gestures.Orientation)(state: https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState, orientation: https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/Orientation)` The default implementation of Pager's pageNestedScrollConnection. | Cmn |

## Constants

### BeyondViewportPageCount

Cmn Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.7.0)

```
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.

## Public functions

### bringIntoViewSpec

Cmn Added in [1.13.0-rc01](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.13.0-rc01)

```
@Composable
fun bringIntoViewSpec(state: PagerState): BringIntoViewSpec
```

Pager's default `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/BringIntoViewSpec` that settles bring into view requests in accordance with the pager's snapping logic.

| Parameters |
|---|---|
| `state: https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState` | state of the pager |

### flingBehavior

Cmn Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.7.0)

```
@Composable
fun flingBehavior(
    state: PagerState,
    pagerSnapDistance: PagerSnapDistance = PagerSnapDistance.atMost(1),
    decayAnimationSpec: DecayAnimationSpec<Float> = rememberSplineBasedDecay(),
    snapAnimationSpec: AnimationSpec<Float> = spring(
                stiffness = Spring.StiffnessMediumLow,
                visibilityThreshold = Int.VisibilityThreshold.toFloat(),
            ),
    snapPositionalThreshold: @FloatRange(from = 0.0, to = 1.0) Float = 0.5f
): TargetedFlingBehavior
```

A `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/snapping/package-summary#snapFlingBehavior(androidx.compose.foundation.gestures.snapping.SnapLayoutInfoProvider,androidx.compose.animation.core.DecayAnimationSpec,androidx.compose.animation.core.AnimationSpec)` 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 |
|---|---|
| `state: https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState` | The `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState` that controls the which to which this FlingBehavior will be applied to. |
| `pagerSnapDistance: https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerSnapDistance = PagerSnapDistance.atMost(1)` | A way to control the snapping destination for this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/package-summary#Pager(androidx.compose.ui.Modifier,androidx.compose.foundation.pager.PagerState,androidx.compose.foundation.layout.PaddingValues,kotlin.Boolean,androidx.compose.foundation.gestures.Orientation,androidx.compose.foundation.gestures.TargetedFlingBehavior,kotlin.Boolean,androidx.compose.foundation.OverscrollEffect,kotlin.Int,androidx.compose.ui.unit.Dp,androidx.compose.foundation.pager.PageSize,androidx.compose.ui.input.nestedscroll.NestedScrollConnection,kotlin.Function1,androidx.compose.ui.Alignment.Horizontal,androidx.compose.ui.Alignment.Vertical,androidx.compose.foundation.gestures.snapping.SnapPosition,androidx.compose.foundation.gestures.BringIntoViewSpec,kotlin.Function2)`. 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 the Pager will bounce back). Use `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerSnapDistance#atMost(kotlin.Int)` to define a maximum number of pages this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/package-summary#Pager(androidx.compose.ui.Modifier,androidx.compose.foundation.pager.PagerState,androidx.compose.foundation.layout.PaddingValues,kotlin.Boolean,androidx.compose.foundation.gestures.Orientation,androidx.compose.foundation.gestures.TargetedFlingBehavior,kotlin.Boolean,androidx.compose.foundation.OverscrollEffect,kotlin.Int,androidx.compose.ui.unit.Dp,androidx.compose.foundation.pager.PageSize,androidx.compose.ui.input.nestedscroll.NestedScrollConnection,kotlin.Function1,androidx.compose.ui.Alignment.Horizontal,androidx.compose.ui.Alignment.Vertical,androidx.compose.foundation.gestures.snapping.SnapPosition,androidx.compose.foundation.gestures.BringIntoViewSpec,kotlin.Function2)` is allowed to fling after scrolling is finished and fling has started. |
| `decayAnimationSpec: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DecayAnimationSpec<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html> = 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: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationSpec<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html> = spring( stiffness = Spring.StiffnessMediumLow, visibilityThreshold = Int.VisibilityThreshold.toFloat(), )` | 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 `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerDefaults#flingBehavior(androidx.compose.foundation.pager.PagerState,androidx.compose.foundation.pager.PagerSnapDistance,androidx.compose.animation.core.DecayAnimationSpec,androidx.compose.animation.core.AnimationSpec,kotlin.Float)` in the last step of the animation to settle the page into position. 2) There was not enough space to run the approach animation. |
| `snapPositionalThreshold: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html = 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. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/TargetedFlingBehavior` | An instance of `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/FlingBehavior` that will perform Snapping to the next page by default. The animation will be governed by the post scroll velocity and the Pager will use either `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerDefaults#flingBehavior(androidx.compose.foundation.pager.PagerState,androidx.compose.foundation.pager.PagerSnapDistance,androidx.compose.animation.core.DecayAnimationSpec,androidx.compose.animation.core.AnimationSpec,kotlin.Float)` or `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerDefaults#flingBehavior(androidx.compose.foundation.pager.PagerState,androidx.compose.foundation.pager.PagerSnapDistance,androidx.compose.animation.core.DecayAnimationSpec,androidx.compose.animation.core.AnimationSpec,kotlin.Float)` to approach the snapped position If a velocity is not high enough the pager will use `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerDefaults#flingBehavior(androidx.compose.foundation.pager.PagerState,androidx.compose.foundation.pager.PagerSnapDistance,androidx.compose.animation.core.DecayAnimationSpec,androidx.compose.animation.core.AnimationSpec,kotlin.Float)` to reach the snapped position. If the velocity is high enough, the Pager will use the logic described in `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerDefaults#flingBehavior(androidx.compose.foundation.pager.PagerState,androidx.compose.foundation.pager.PagerSnapDistance,androidx.compose.animation.core.DecayAnimationSpec,androidx.compose.animation.core.AnimationSpec,kotlin.Float)` and `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerDefaults#flingBehavior(androidx.compose.foundation.pager.PagerState,androidx.compose.foundation.pager.PagerSnapDistance,androidx.compose.animation.core.DecayAnimationSpec,androidx.compose.animation.core.AnimationSpec,kotlin.Float)`. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/snapping/package-summary#snapFlingBehavior(androidx.compose.foundation.gestures.snapping.SnapLayoutInfoProvider,androidx.compose.animation.core.DecayAnimationSpec,androidx.compose.animation.core.AnimationSpec)` | for more information on what which parameter controls in the overall snapping animation. The animation specs used by the fling behavior will depend on 2 factors: 1. The gesture velocity. 2. The target page proposed by `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerDefaults#flingBehavior(androidx.compose.foundation.pager.PagerState,androidx.compose.foundation.pager.PagerSnapDistance,androidx.compose.animation.core.DecayAnimationSpec,androidx.compose.animation.core.AnimationSpec,kotlin.Float)`. If you're using single page snapping (the most common use case for `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/package-summary#Pager(androidx.compose.ui.Modifier,androidx.compose.foundation.pager.PagerState,androidx.compose.foundation.layout.PaddingValues,kotlin.Boolean,androidx.compose.foundation.gestures.Orientation,androidx.compose.foundation.gestures.TargetedFlingBehavior,kotlin.Boolean,androidx.compose.foundation.OverscrollEffect,kotlin.Int,androidx.compose.ui.unit.Dp,androidx.compose.foundation.pager.PageSize,androidx.compose.ui.input.nestedscroll.NestedScrollConnection,kotlin.Function1,androidx.compose.ui.Alignment.Horizontal,androidx.compose.ui.Alignment.Vertical,androidx.compose.foundation.gestures.snapping.SnapPosition,androidx.compose.foundation.gestures.BringIntoViewSpec,kotlin.Function2)`), there won't be enough space to actually run a decay animation to approach the target page, so the Pager will always use the snapping animation from `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerDefaults#flingBehavior(androidx.compose.foundation.pager.PagerState,androidx.compose.foundation.pager.PagerSnapDistance,androidx.compose.animation.core.DecayAnimationSpec,androidx.compose.animation.core.AnimationSpec,kotlin.Float)`. If you're using multi-page snapping (this means you're abs(targetPage - currentPage) \> 1) the Pager may use `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerDefaults#flingBehavior(androidx.compose.foundation.pager.PagerState,androidx.compose.foundation.pager.PagerSnapDistance,androidx.compose.animation.core.DecayAnimationSpec,androidx.compose.animation.core.AnimationSpec,kotlin.Float)` or `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerDefaults#flingBehavior(androidx.compose.foundation.pager.PagerState,androidx.compose.foundation.pager.PagerSnapDistance,androidx.compose.animation.core.DecayAnimationSpec,androidx.compose.animation.core.AnimationSpec,kotlin.Float)` to approach the targetPage, it will depend on the velocity generated by the triggering gesture. If the gesture has a high enough velocity to approach the target page, the Pager will use `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerDefaults#flingBehavior(androidx.compose.foundation.pager.PagerState,androidx.compose.foundation.pager.PagerSnapDistance,androidx.compose.animation.core.DecayAnimationSpec,androidx.compose.animation.core.AnimationSpec,kotlin.Float)` followed by `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerDefaults#flingBehavior(androidx.compose.foundation.pager.PagerState,androidx.compose.foundation.pager.PagerSnapDistance,androidx.compose.animation.core.DecayAnimationSpec,androidx.compose.animation.core.AnimationSpec,kotlin.Float)` for the final step of the animation. If the gesture doesn't have enough velocity, the Pager will use `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerDefaults#flingBehavior(androidx.compose.foundation.pager.PagerState,androidx.compose.foundation.pager.PagerSnapDistance,androidx.compose.animation.core.DecayAnimationSpec,androidx.compose.animation.core.AnimationSpec,kotlin.Float)` + `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerDefaults#flingBehavior(androidx.compose.foundation.pager.PagerState,androidx.compose.foundation.pager.PagerSnapDistance,androidx.compose.animation.core.DecayAnimationSpec,androidx.compose.animation.core.AnimationSpec,kotlin.Float)` in a similar fashion. |

### pageNestedScrollConnection

Cmn Added in [1.6.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.6.0)

```
@Composable
fun pageNestedScrollConnection(state: PagerState, orientation: Orientation): NestedScrollConnection
```

The default implementation of Pager's pageNestedScrollConnection.

| Parameters |
|---|---|
| `state: https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState` | state of the pager |
| `orientation: https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/Orientation` | The orientation of the pager. This will be used to determine which direction the nested scroll connection will operate and react on. |