Is there any way to animate `Offset` in a similar ...
# compose
a
Is there any way to animate
Offset
in a similar way to
keyframes
, but with smooth curvy lines between points instead of straight lines?
👍 1
r
@hoford
p
Any news on that one?
d
Could you file a feature request on this. A variation of
keyframes
that also does curve fitting based on the given points should be feasible.
r
@Arkadii Ivanov if you want to do it by hand it’s not very complicated, you would effectively animate a 0..1 value and evaluate for instance a BĂ©zier curve equation to get the final
Offset
p
I am using
TargetBasedAnimation
to know exact position of animated object in canvas.
Copy code
val animationConfig: TargetBasedAnimation<DpOffset, AnimationVector2D>
        get() = TargetBasedAnimation(
            animationSpec = tween(durationMillis = lifespan, easing = easing),
            typeConverter = DpOffset.VectorConverter,
            initialValue = startPoint,
            targetValue = endPoint
        )
How can I change that or use
keyframes
to have a Bezier curve path for my object from initialValue to targetValue?
a
If I understand it correctly, Bezier curve won't go through key frames.
r
@Arkadii Ivanov Your key frames in this case are P0 and P3
P1 and P2 are “control points”, that you use to shape the curve
a
Got it. I wanted something simpler. Like I define key frames (points), and it animates smoothly. Will file feature request.
r
It’s
 not that simple 🙂
😄 1
@hoford has been working on something like this
d
I'll make sure @hoford gets cc'ed on that feature request in case he doesn't see this.
@Arkadii Ivanov could you post the issue id here once you file the FR? Thanks
h
MotionLayout much of what you are looking. It supports keyframes for motions. If you are looking the raw algorithms involved. It is a MonotonicSpline (which has some properties which make it more suitable for animations) MotionTags videos on KeyAttributes & KeyPosition provide a good overview of the capability. https://www.youtube.com/playlist?list=PLWz5rJ2EKKc-bcyUTIFAr97ZtRkwM7S4y Demos of the Compose version of MotionLayout are here: https://github.com/androidx/constraintlayout/tree/main/demoProjects/ExamplesComposeMotionLayout
a
@Doris Liu I have submitted a feature request, thanks! b/292114811
🙏 1