https://kotlinlang.org logo
#compose
Title
# compose
k

Kazemihabib1996

04/29/2020, 4:48 PM
I can't understand this version of
fling
animation
Copy code
fun AnimatedFloat.fling(
    startVelocity: Float,
    decay: DecayAnimation = ExponentialDecay(),
    adjustTarget: (Float) -> TargetAnimation?,
    onEnd: OnAnimationEnd? = null
)
it accepts a
startVelocity
and
decay
so far it makes sence. but it also accepts an
adjustTarget
that's the what I can't understand, setting new target with new animation inside fling animation?
m

matvei

04/29/2020, 4:55 PM
It can be used to adjust target calculated by the
decay
. For example, imagine you have some bounds and want to nicely fling to the bound, not at the random point where decay stopped it. That's when you can adjust target so fling will end where you need it to
One more example: you have BottomSheet that can be opened fullscreen, or half screen. You can implement it in the way that if user flings and your original target passed the certain threshold, you animate to the fullscreen bound, otherwise to the halfscreen
k

Kazemihabib1996

04/29/2020, 5:23 PM
@matvei Thank you, nice explanation and example. I've been thinking some how these animations are merged !!!! and that was confusing me. but after your explanation and reading the source of it I realized it just uses the animation of
adjustTarget
if the
targetAnimation
is not null.
m

matvei

04/29/2020, 5:24 PM
Yep, for most of the fling scenarios
null
will just work fine 🙂
👍 1
6 Views