mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-18 06:13:49 +00:00
27 lines
878 B
Kotlin
27 lines
878 B
Kotlin
package dev.inmo.micro_utils.android.pickers
|
|
|
|
import androidx.compose.animation.core.*
|
|
|
|
internal suspend fun Animatable<Float, AnimationVector1D>.fling(
|
|
initialVelocity: Float,
|
|
animationSpec: DecayAnimationSpec<Float>,
|
|
adjustTarget: ((Float) -> Float)?,
|
|
block: (Animatable<Float, AnimationVector1D>.() -> Unit)? = null,
|
|
): AnimationResult<Float, AnimationVector1D> {
|
|
val targetValue = animationSpec.calculateTargetValue(value, initialVelocity)
|
|
val adjustedTarget = adjustTarget?.invoke(targetValue)
|
|
|
|
return if (adjustedTarget != null) {
|
|
animateTo(
|
|
targetValue = adjustedTarget,
|
|
initialVelocity = initialVelocity,
|
|
block = block
|
|
)
|
|
} else {
|
|
animateDecay(
|
|
initialVelocity = initialVelocity,
|
|
animationSpec = animationSpec,
|
|
block = block,
|
|
)
|
|
}
|
|
} |