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

Add support for animating startPoint and endPoint of radial gradients #1798

Merged
merged 6 commits into from
Nov 4, 2022

Conversation

calda
Copy link
Member

@calda calda commented Nov 3, 2022

This PR adds support for animating the startPoint and endPoint of radial gradients. We can do this by combining the two sets of keyframes into a single KeyframeGroup, manually interpolating them if necessary. Fixes #1762.

I took this opportunity to consolidate the manual interpolation functionality into Keyframes.combined, and also adopt this in most other places where we were using KeyframeGroup.exactlyOneKeyframe.

Before After
2022-11-03 11 31 26 2022-11-03 11 30 33

/// Combines the given keyframe groups of `Keyframe<T>`s into a single keyframe group of of `Keyframe<[T]>`s
/// - If all of the `KeyframeGroup`s have the exact same animation timing, the keyframes are merged
/// - Otherwise, the keyframes are manually interpolated at each frame in the animation
static func combined<T>(_ allGroups: [KeyframeGroup<T>]) -> KeyframeGroup<[T]>
Copy link
Member Author

Choose a reason for hiding this comment

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

These methods were renamed from Keyframes.combinedIfPossible(...) -> KeyframeGroup? to Keyframes.combined(...) -> KeyframeGroup

else {
// If the keyframes don't all share the same timing information,
// we have to interpolate the value at each individual frame
return Keyframes.manuallyInterpolated(allGroups, makeCombinedResult: makeCombinedResult)
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the only new logic in this method (previously this was just return nil)

return KeyframeGroup(keyframes: combinedKeyframes)
}

private static func manuallyInterpolated<CombinedResult>(
Copy link
Member Author

Choose a reason for hiding this comment

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

This method is new

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 great! Nice cleanup too

/// Combines the given keyframe groups of `Keyframe<T>`s into a single keyframe group of of `Keyframe<[T]>`s
/// - If all of the `KeyframeGroup`s have the exact same animation timing, the keyframes are merged
/// - Otherwise, the keyframes are manually interpolated at each frame in the animation
static func combined<T1, T2, T3, T4, T5, T6, T7, CombinedResult>(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could really use "row polymorphism" for this one! 😂

Copy link
Member Author

Choose a reason for hiding this comment

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

please, variadic generics when

@calda calda merged commit abe71a7 into master Nov 4, 2022
@calda calda deleted the cal--interpolated-keyframes branch November 4, 2022 23:56
calda added a commit that referenced this pull request Dec 1, 2022
iago849 pushed a commit to atteamapps/lottie-ios that referenced this pull request Feb 8, 2024
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.

Add support for animating multiple keyframes for gradient startPoint with the Core Animation renderer
2 participants