# TargetedFlingBehavior

# TargetedFlingBehavior

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

  ```
  interface TargetedFlingBehavior : FlingBehavior
  ```

*** ** * ** ***

Interface to specify fling behavior with additional information about its animation target.

## Summary

|                                      ### Public functions                                      |
|------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----|
| `open suspend `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | [ScrollScope](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollScope)`.`[performFling](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/TargetedFlingBehavior#(androidx.compose.foundation.gestures.ScrollScope).performFling(kotlin.Float))`(initialVelocity: `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)`)` Perform settling via fling animation with given velocity and suspend until fling has finished.                                                                                                                                                                                                                                | Cmn |
| `suspend `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)      | [ScrollScope](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollScope)`.`[performFling](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/TargetedFlingBehavior#(androidx.compose.foundation.gestures.ScrollScope).performFling(kotlin.Float,kotlin.Function1))`(` ` initialVelocity: `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)`,` ` onRemainingDistanceUpdated: (`[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)`) `->` `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) `)` Perform settling via fling animation with given velocity and suspend until fling has finished. | Cmn |

## Public functions

### performFling

Cmn  
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/TargetedFlingBehavior.kt+function:performFling)  

```
open suspend fun ScrollScope.performFling(initialVelocity: Float): Float
```

Perform settling via fling animation with given velocity and suspend until fling has finished.

This functions is called with[ScrollScope](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollScope)to drive the state change of the[androidx.compose.foundation.gestures.ScrollableState](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollableState)via[ScrollScope.scrollBy](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollScope#scrollBy(kotlin.Float)).

This function must return correct velocity left after it is finished flinging in order to guarantee proper nested scroll support.  

|                                             Parameters                                             |
|----------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `initialVelocity: `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | velocity available for fling in the orientation specified in[androidx.compose.foundation.gestures.scrollable](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.ui.Modifier).scrollable(androidx.compose.foundation.gestures.ScrollableState,androidx.compose.foundation.gestures.Orientation,kotlin.Boolean,kotlin.Boolean,androidx.compose.foundation.gestures.FlingBehavior,androidx.compose.foundation.interaction.MutableInteractionSource))that invoked this method. |

|                                     Returns                                     |
|---------------------------------------------------------------------------------|----------------------------------------------------|
| [Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | remaining velocity after fling operation has ended |

### performFling

Cmn  
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/TargetedFlingBehavior.kt+function:performFling)  

```
suspend fun ScrollScope.performFling(
    initialVelocity: Float,
    onRemainingDistanceUpdated: (Float) -> Unit
): Float
```

Perform settling via fling animation with given velocity and suspend until fling has finished. Use[onRemainingDistanceUpdated](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/TargetedFlingBehavior#(androidx.compose.foundation.gestures.ScrollScope).performFling(kotlin.Float,kotlin.Function1))to report the status of the ongoing fling animation and the remaining amount of scroll offset.

This functions is called with[ScrollScope](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollScope)to drive the state change of the[androidx.compose.foundation.gestures.ScrollableState](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollableState)via[ScrollScope.scrollBy](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollScope#scrollBy(kotlin.Float)).

This function must return the correct velocity left after it is finished flinging in order to guarantee proper nested scroll support.  

|                                                                                              Parameters                                                                                              |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `initialVelocity: `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)                                                                                                   | velocity available for fling in the orientation specified in[androidx.compose.foundation.gestures.scrollable](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.ui.Modifier).scrollable(androidx.compose.foundation.gestures.ScrollableState,androidx.compose.foundation.gestures.Orientation,kotlin.Boolean,kotlin.Boolean,androidx.compose.foundation.gestures.FlingBehavior,androidx.compose.foundation.interaction.MutableInteractionSource))that invoked this method. |
| `onRemainingDistanceUpdated: (`[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)`) `->` `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | a lambda that will be called anytime the distance to the settling offset is updated. The settling offset in pixels is passed to this lambda an it represents the final offset where this fling will stop and may change depending on the snapping animation progression.                                                                                                                                                                                                                                                                       |

|                                     Returns                                     |
|---------------------------------------------------------------------------------|----------------------------------------------------|
| [Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | remaining velocity after fling operation has ended |