Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support animating multiple properties of shape bezier paths #1690

Merged
merged 5 commits into from
Aug 3, 2022

Conversation

calda
Copy link
Member

@calda calda commented Aug 2, 2022

I noticed the animations added in #1688 were marked as unsupported by the Core Animation rendering engine, even though they rendered correctly.

This PR updates the Core Animation rendering engine to support animating multiple properties of shape bezier paths. Now those animations are fully supported by the new engine.

To render shapes, we basically have to combine multiple KeyframeGroup<Vector3D> / KeyframeGroup<Vector1D>s into a single KeyframeGroup<BezierPath>. Originally we implemented this by just taking the keyframe timing information from one component and discarding the rest. Instead we can use Keyframes.combinedIfPossible to merge together all of the keyframes groups if they have the same timing information.

value: { position in
// We can only use one set of keyframes to animate a given CALayer keypath,
// so we currently animate `position` and ignore any other keyframes.
// TODO: Is there a way to support this properly?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// TODO: Is there a way to support this properly?

Good news, yes! 😝

@calda calda force-pushed the cal--improved-shape-animations branch from 108d9a8 to 11b73a8 Compare August 2, 2022 22:15
@calda calda force-pushed the cal--improved-shape-animations branch from 11b73a8 to ba14b04 Compare August 2, 2022 22:18
Copy link
Collaborator

@erichoracek erichoracek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just one question about whether we can make it safer using generics

Comment on lines 39 to 43
let combinedKeyframes = Keyframes.combinedIfPossible(size, position) { untypedValues in
Keyframe(
size: untypedValues[0] as! Vector3D,
position: untypedValues[1] as! Vector3D)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused what's going on here, why are we force casting these to Vector3D if both params are of type Vector3D? Is this due to limitations around variadic parameters and generics? Wondering if we could instead just make multiple arities of this function with tuples, similar to how Combine works with operators, since this feels a bit brittle/unsafe as-is

Copy link
Collaborator

@erichoracek erichoracek Aug 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you answered this before I submitted the review, feel free to merge as-is if you'd like 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having multiple arities is an interesting idea, I'll try it out and see how it goes. It would definitely be easier to understand the callsite without this casting.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion, this worked out nicely: 96980ab

This case is now just:

let combinedKeyframes = Keyframes.combinedIfPossible(
  size, position,
  makeCombinedResult: Ellipse.Keyframe.init)

@calda calda enabled auto-merge (squash) August 3, 2022 16:15
@calda calda force-pushed the cal--improved-shape-animations branch from d58ff0c to 26d7fa8 Compare August 3, 2022 16:59
@calda calda merged commit 897f243 into master Aug 3, 2022
@calda calda deleted the cal--improved-shape-animations branch August 3, 2022 17:18
MoroziOS pushed a commit to MoroziOS/tmg-lottie-ios that referenced this pull request May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants