# SnapLayoutInfoProvider

# SnapLayoutInfoProvider

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/gestures/snapping/SnapLayoutInfoProvider.kt+class:androidx.compose.foundation.gestures.snapping.SnapLayoutInfoProvider)  
Added in[1.3.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.3.0)
Common/All
  - Cmn  

  ```
  interface SnapLayoutInfoProvider
  ```

*** ** * ** ***

Provides information about the layout that is using a[snapFlingBehavior](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)). The provider should give the following information:

1. Snapping offset: The next snap position offset. This needs to be provided by the layout where the snapping is happened and will represent the final settling position of this layout.

2. Approach offset: An offset to be consumed before snapping to a defined bound. If not overridden this will provide a decayed snapping behavior.

In snapping, the approach offset and the snapping offset can be used to control how a snapping animation will look in a given layout. The complete snapping animation can be split into 2 phases: approach and snapping.

Approach: animate to the offset returned by[calculateApproachOffset](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/snapping/SnapLayoutInfoProvider#calculateApproachOffset(kotlin.Float,kotlin.Float)). This will use a decay animation if possible, otherwise the snap animation. Snapping: once the approach offset is reached, snap to the offset returned by[calculateSnapOffset](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/snapping/SnapLayoutInfoProvider#calculateSnapOffset(kotlin.Float))using the snap animation.

## Summary

|                                  ### Public functions                                  |
|----------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----|
| `open `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | [calculateApproachOffset](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/snapping/SnapLayoutInfoProvider#calculateApproachOffset(kotlin.Float,kotlin.Float))`(velocity: `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)`, decayOffset: `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)`)` Calculate the distance to navigate before settling into the next snapping bound. | Cmn |
| [Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)        | [calculateSnapOffset](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/snapping/SnapLayoutInfoProvider#calculateSnapOffset(kotlin.Float))`(velocity: `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)`)` Given a target placement in a layout, the snapping offset is the next snapping position this layout can be placed in.                                                                                 | Cmn |

## Public functions

### calculateApproachOffset

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

```
open fun calculateApproachOffset(velocity: Float, decayOffset: Float): Float
```

Calculate the distance to navigate before settling into the next snapping bound. By default this is[decayOffset](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/snapping/SnapLayoutInfoProvider#calculateApproachOffset(kotlin.Float,kotlin.Float))a suggested offset given by[snapFlingBehavior](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))to indicate where the animation would naturally decay if using[velocity](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/snapping/SnapLayoutInfoProvider#calculateApproachOffset(kotlin.Float,kotlin.Float)). Returning a value higher than[decayOffset](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/snapping/SnapLayoutInfoProvider#calculateApproachOffset(kotlin.Float,kotlin.Float))is valid and will force[snapFlingBehavior](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))to use a target based animation spec to run the approach phase since we won't be able to naturally decay to the proposed offset. If a value smaller than or equal to[decayOffset](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/snapping/SnapLayoutInfoProvider#calculateApproachOffset(kotlin.Float,kotlin.Float))is returned[snapFlingBehavior](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))will run a decay animation until it reaches the returned value. If zero is specified, that means there won't be an approach phase and there will only be snapping.  

|                                           Parameters                                           |
|------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------|
| `velocity: `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)    | The current fling movement velocity. You can use this to calculate a velocity based offset. |
| `decayOffset: `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | A suggested offset indicating where the animation would naturally decay to.                 |

### calculateSnapOffset

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

```
fun calculateSnapOffset(velocity: Float): Float
```

Given a target placement in a layout, the snapping offset is the next snapping position this layout can be placed in. The target placement should be in the direction of[velocity](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/snapping/SnapLayoutInfoProvider#calculateSnapOffset(kotlin.Float)).  

|                                         Parameters                                          |
|---------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------|
| `velocity: `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | The current fling movement velocity. This may change throughout the fling animation. |