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

Vsevolod Ganin

02/24/2021, 6:35 PM
In alpha12 I used the factory function
FlingConfig
which produces function
adjustTarget
from the list of
anchors
. Do I need to recreate it manually now or is there an analogue?
m

matvei

02/24/2021, 6:59 PM
Hey! Yeah, I remember we chatted a bit about it the other day. FlingConfig is no more and there's actually no need for it. If you need to swipe between the list of anchors, please try to use
swipeable
If you were using FlingConfig with scroll-based APIs, there's a better, suspending version called
FlingBehaviour
If you are using FlingConfig to precalculate your own anchors in a custom way and don't need a swipeable and the package that comes with it: you can just make it happen with the APIs that exist in beta 🙂 You need to calculate the approximate target yourself using AnimationSpec of your choice, and then adjust it to the anchor to get the real target value to animate to. Them, choose the API from the animation stack to use (Animatable, AnimationState, transition even?) and animate! 🙂 It gives even more control to you much overhead compared to the FlingConfig. Hit me up with any question that you have!
v

Vsevolod Ganin

02/24/2021, 7:32 PM
Thanks for great explanation Matvei! I’m on my way to reimplement this tiny little behavior, and my codebase will be free from the
FlingConfig
for good at last 😁 I have a couple of questions if you don’t mind. • What is the default decay spec for true androidish fling feel? There was some factory function like
androidFlingSomething
though I may be wrong.
SwipeableDefaults
suggests just
SpringSpec<Float>()
I believe. So it’s just that? • I’m getting a bit lost between decay specs. Earlier in alpha12 I discovered that there is some generalization over
FloatDecayAnimationSpec
that is
VectorizedDecayAnimationSpec
. And there is
DecayAnimationSpec
which produces
VectorizedDecayAnimationSpec
. Is there a plan to get rid of
FloatDecayAnimationSpec
in the future? •
FlingBehaviour
sounds really interesting. Unfortunately it seems I am not able to find the corresponding APIs... Could you please direct me to any doc page mentioning it?
a

Albert Chang

02/25/2021, 8:56 AM
It is
FlingBehavior
. Unfortunately I've found a bug so you may need some workarounds if you want to use it.
v

Vsevolod Ganin

02/25/2021, 9:46 AM
Thanks! Now I found it
m

matvei

02/25/2021, 1:01 PM
Sure, no problem 🙂 • the default decay spec is here: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]tion/DefaultDecayAnimationSpec.kt?q=DefaultDecayAnimationSpec The idea is that it will represent eventually the natural decay spec for the platform the code is running on, and for android it would be the decay we use for scroll/etc •
VectorizedDecayAnimationSpec
is the decay spec for a generic vectorized value. Vectorized value can have more than one value changing at a time (imagine Color which is a 4d vector since you are animating r,g,b and alpha). FloatDecayAnimationSpec is a particular 1dimentional float based spec, which is used commonly since we usually decay float pixels in the scroll/viewpager/etc. Can be quite confusing on the first glance, but in general it's a powerful toolset for anything you might want to animate 🙂
🙏 1
8 Views