Skip to content

Conversation

andyf-canva
Copy link
Collaborator

@andyf-canva andyf-canva commented Nov 29, 2024

Issue here -> #3

From a discussion between @tinyjin and @andyf-canva...

I have a question, Is there a component like based on UIView or SwiftUI?
Unfortunately not 😢. ... if people want to use this API then they need to manually iterate through the frames and create a LottieRenderer themselves. Which is a good point to make: if most consumers of Lottie expect to be using this in a UIKit/SwiftUI context, they may struggle to use the package.

This PR introduces helper a SwiftUI View and UIKit UIView to promote easier adoption of the LottieRenderer-based rendering implementation.

TODO:

  • Clean up ViewModel
  • Write documentation
  • Write tests
  • Update documentation

@andyf-canva
Copy link
Collaborator Author

@tinyjin @hermet - just a heads up on my progress with creating these helpers views. Apologies - we've been extremely busy here at Canva so haven't had time to get to this. Will look to wrap this up over the next few weeks. 👍

@hermet hermet added the enhancement New feature or request label Dec 2, 2024
@andyf-canva
Copy link
Collaborator Author

Hey folks! Sorry it's been a mad rush for the end of the year. I'll pick this back up in the New Year and can get it merged 🙏

@hermet
Copy link
Member

hermet commented Dec 19, 2024

@andyf-canva no worry, wish you a merry christmas!

@andyf-canva
Copy link
Collaborator Author

Another follow up, we've been so busy with our push to Canva Create I haven't had any time for this. Luckily we've got a bit of time over the next few weeks that I can spend cleaning this up.

@hermet is there still appetite for introducing this API into the core thorvg module?

@hermet
Copy link
Member

hermet commented Mar 19, 2025

@andyf-canva Hello, no worries! 🙂 If the PR is ready, please remove the draft status so we can start the review process. Thanks!

@hermet hermet requested a review from Copilot September 3, 2025 14:23
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR creates helper SwiftUI and UIKit views to simplify the usage of the LottieRenderer-based rendering implementation, addressing the issue that consumers previously had to manually iterate through frames and create renderers themselves.

  • Introduces a LottieViewModel that manages animation state and frame rendering
  • Adds LottieView for SwiftUI integration with automatic animation lifecycle management
  • Provides LottieUIKitView for UIKit integration with similar functionality

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
swift/Resources/test.json Adds test Lottie animation data for development and preview
swift/LottieViewModel.swift Core view model handling frame rendering, animation timing, and image conversion
swift/LottieView.swift SwiftUI wrapper view with automatic animation start/stop on appear/disappear
swift/LottieUIKitView.swift UIKit wrapper view providing similar functionality for UIKit contexts
swift/Lottie.swift Adds getSize() method to retrieve animation dimensions
Package.swift Updates package configuration to include Resources directory

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

timer = nil
}

// TODO: Handle errors propery here.
Copy link

Copilot AI Sep 3, 2025

Choose a reason for hiding this comment

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

There's a typo in the comment: 'propery' should be 'properly'.

Suggested change
// TODO: Handle errors propery here.
// TODO: Handle errors properly here.

Copilot uses AI. Check for mistakes.

Comment on lines +60 to +61
print(error)
fatalError("Rendering error.")
Copy link

Copilot AI Sep 3, 2025

Choose a reason for hiding this comment

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

The error message 'Rendering error.' is too generic and doesn't provide useful debugging information. Consider including the actual error details or a more descriptive message.

Suggested change
print(error)
fatalError("Rendering error.")
fatalError("Rendering error: \(error)")

Copilot uses AI. Check for mistakes.

Comment on lines +70 to +71
print("UI IMAGE CAST ERROR")
fatalError("UIImage cast error.")
Copy link

Copilot AI Sep 3, 2025

Choose a reason for hiding this comment

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

The error messages are inconsistent in style (all caps vs sentence case) and not descriptive. Consider using a consistent format and providing more context about what failed during the UIImage creation.

Suggested change
print("UI IMAGE CAST ERROR")
fatalError("UIImage cast error.")
print("Failed to create UIImage from buffer. Buffer count: \(buffer.count), size: \(size), pixelFormat: .argb")
fatalError("Failed to create UIImage from buffer with size \(size) and pixelFormat .argb.")

Copilot uses AI. Check for mistakes.

Comment on lines +37 to +41
viewModel.$renderedFrame
.sink { [weak self] image in
self?.imageView.image = image
}
.store(in: &cancellables)
Copy link

Copilot AI Sep 3, 2025

Choose a reason for hiding this comment

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

The subscription to viewModel.$renderedFrame is created every time startAnimating() is called, but previous subscriptions are not cancelled. This will create multiple subscriptions and potential memory leaks. Consider cancelling existing subscriptions first or moving this subscription to setupView().

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants