<div class='type'>Function</div>


<a id='references'></a>


<h2 id="snapflingbehavior-snaplayoutinfoprovider-decayanimationspec-snapanimationspec">snapFlingBehavior</h2>

<div class='sourceset sourceset-common'>Common</div>


```kotlin
fun snapFlingBehavior(
    snapLayoutInfoProvider: SnapLayoutInfoProvider,
    decayAnimationSpec: DecayAnimationSpec<Float>,
    snapAnimationSpec: AnimationSpec<Float>,
): TargetedFlingBehavior
```


A `TargetedFlingBehavior` that performs snapping to a given position in a layout.

You can use `SnapLayoutInfoProvider.calculateApproachOffset` to indicate that snapping should
happen after this offset. If the velocity generated by the fling is high enough to get there,
we'll use `decayAnimationSpec` to get to that offset and then we'll snap to the next bound
calculated by `SnapLayoutInfoProvider.calculateSnapOffset` using `snapAnimationSpec`.

If the velocity is not high enough, we'll use `snapAnimationSpec` to approach and the same spec
to snap into place.

Please refer to the sample to learn how to use this API.

#### Parameters

| | |
| --- | --- |
| snapLayoutInfoProvider | The information about the layout being snapped. |
| decayAnimationSpec | The animation spec used to approach the target offset when the fling velocity is large enough. Large enough means large enough to naturally decay. |
| snapAnimationSpec | The animation spec used to finally snap to the correct bound. |