Skip to content

Conversation

@andyf-canva
Copy link
Owner

@andyf-canva andyf-canva commented Feb 26, 2024

Changes

This PR refactors the Lottie type by using the internal types introduced in the previous PR (#9), setting ourselves up for the final PR where we will introduce the the new LottieRenderer type.

Internal types

These changes are quite simple, moving all of the rendering logic out of the Lottie type, focusing the Lottie type on creating a new Animation instance and loading data into the Picture instance associated to that Animation.

As all of these new types are internal, this means that the public API has minimal changes. For reference, the old public API is here.

Note: You may notice that the renderFrame function has gone, this will be addressed by the next PR as this logic will be moved into it's own type LottieRenderer.

/// Shorthand alias for the buffer type, representing image pixel data in a mutable pointer to UInt32.
public typealias Buffer = UnsafeMutablePointer<UInt32>

/// Object used to load and render Lottie frames.
public class Lottie {

    /// The number of frames in the Lottie animation.
    public let numberOfFrames: Int

    /// The duration of the Lottie animation.
    public let duration: CMTime

    /// Create a `Lottie` instance from a file path.
    /// - Parameter path: The file path of the Lottie animation to load.
    public convenience init(path: String) throws

    /// Create a `Lottie` instance from a raw string.
    /// - Parameter string: The raw string containing the Lottie animation data.
    public convenience init(string: String) throws
}

Larger refactoring

As mentioned, this is part of a larger factor across the entire Swift wrapper. This Lottie type will be used with the new LottieRenderer type.

Look at the PR train below for more details.

PR Train 🚂

  1. Refactoring Swift Wrapper: Introduce internal Swift types #9
  2. Refactoring Swift Wrapper: Refactor Lottie type #10 <- YOU ARE HERE
  3. Refactoring Swift Wrapper: Introduce LottieRenderer #11

Comment on lines +5 to +7
/// Shorthand alias for the buffer type, representing image pixel data in a mutable pointer to UInt32.
public typealias Buffer = UnsafeMutablePointer<UInt32>

Copy link
Owner Author

Choose a reason for hiding this comment

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

Just had to add this in for the time being, it will be moved to LottieRenderer in the next PR.

@@ -1,22 +1,8 @@
import CoreGraphics
import CoreMedia

Copy link
Owner Author

Choose a reason for hiding this comment

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

The diff for this file is a bit messy. I'd recommend just looking at the file itself.

@andyf-canva andyf-canva changed the base branch from andyf-introduce-new-internal-types to main February 29, 2024 05:54
@andyf-canva andyf-canva force-pushed the andyf-refactor-lottie-type branch from ac94d2c to e6da3c1 Compare February 29, 2024 07:22
Copy link
Collaborator

@ray-canva ray-canva left a comment

Choose a reason for hiding this comment

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

LGTM

@andyf-canva andyf-canva merged commit 50ea8ab into main Mar 5, 2024
@andyf-canva andyf-canva deleted the andyf-refactor-lottie-type branch March 8, 2024 07:09
andyf-canva added a commit that referenced this pull request Apr 29, 2024
* Introduce internal Swift types

* Remove Engine from this PR

* Refactor Lottie to use internal types

* Adopt changes from past PR
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.

4 participants