androidx.compose.foundation.animation
Classes
FlingConfig |
Class to specify fling behavior. |
FloatAndroidFlingDecaySpec |
A native Android fling curve decay. |
Type-aliases
AndroidFlingDecaySpec |
Top-level functions summary
FlingConfig |
FlingConfig(anchors: List<Float>, animationSpec: AnimationSpec<Float> = SpringSpec(), decayAnimation: FloatDecayAnimationSpec = FloatExponentialDecaySpec()) Create fling config with anchors will make sure that after drag has ended, the value will be animated to one of the points from the predefined list. |
DecayAnimationSpec<T> |
androidFlingDecay(density: Density) Creates a DecayAnimationSpec using the native Android fling decay. |
FlingConfig |
defaultFlingConfig(adjustTarget: (Float) -> TargetAnimation? = { null }) Default FlingConfig curve. |
Extension functions summary
For AnimatedFloat | |
Unit |
AnimatedFloat.fling(startVelocity: Float, config: FlingConfig, onAnimationEnd: OnAnimationEnd? = null) Starts a fling animation with the specified starting velocity and fling configuration. |
For Scrollable | |
suspend Float |
Scrollable.smoothScrollBy(value: Float, spec: AnimationSpec<Float> = spring()) Smooth scroll by value pixels. |
Top-level functions
FlingConfig
fun FlingConfig(
anchors: List<Float>,
animationSpec: AnimationSpec<Float> = SpringSpec(),
decayAnimation: FloatDecayAnimationSpec = FloatExponentialDecaySpec()
): FlingConfig
Create fling config with anchors will make sure that after drag has ended, the value will be animated to one of the points from the predefined list.
It takes velocity into account, though value will be animated to the closest point in provided list considering velocity.
Parameters | |
---|---|
anchors: List<Float> | set of anchors to animate to |
animationSpec: AnimationSpec<Float> = SpringSpec() | animation which will be used for animations |
decayAnimation: FloatDecayAnimationSpec = FloatExponentialDecaySpec() | decay animation to be used to calculate closest point in the anchors set considering velocity. |
androidFlingDecay
fun <T> androidFlingDecay(density: Density): DecayAnimationSpec<T>
Creates a DecayAnimationSpec using the native Android fling decay. This can then be used to animate any type T.
Parameters | |
---|---|
density: Density | density of the display |
defaultFlingConfig
@Composable fun defaultFlingConfig(adjustTarget: (Float) -> TargetAnimation? = { null }): FlingConfig
Default FlingConfig curve.
Parameters | |
---|---|
adjustTarget: (Float) -> TargetAnimation? = { null } | callback to be called at the start of fling so the final value for fling can be adjusted |
Extension functions
fling
fun AnimatedFloat.fling(
startVelocity: Float,
config: FlingConfig,
onAnimationEnd: OnAnimationEnd? = null
): Unit
Starts a fling animation with the specified starting velocity and fling configuration.
Parameters | |
---|---|
startVelocity: Float | Starting velocity of the fling animation |
config: FlingConfig | configuration that specifies fling behaviour |
onAnimationEnd: OnAnimationEnd? = null | callback to be invoked when fling finishes by decay or being interrupted by gesture input. Consider second boolean param "cancelled" to know what happened. |
smoothScrollBy
suspend fun Scrollable.smoothScrollBy(
value: Float,
spec: AnimationSpec<Float> = spring()
): Float
Smooth scroll by value pixels.
Cancels the currently running scroll, if any, and suspends until the cancellation is complete.
Parameters | |
---|---|
value: Float | delta to scroll by |
spec: AnimationSpec<Float> = spring() | AnimationSpec to be used for this smooth scrolling |
Return | |
---|---|
the amount of scroll consumed |