-
-
Notifications
You must be signed in to change notification settings - Fork 1
Create helper SwiftUI and UIKit Views #4
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
base: main
Are you sure you want to change the base?
Conversation
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 🙏 |
@andyf-canva no worry, wish you a merry christmas! |
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? |
@andyf-canva Hello, no worries! 🙂 If the PR is ready, please remove the draft status so we can start the review process. Thanks! |
There was a problem hiding this 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. |
Copilot
AI
Sep 3, 2025
There was a problem hiding this comment.
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'.
// TODO: Handle errors propery here. | |
// TODO: Handle errors properly here. |
Copilot uses AI. Check for mistakes.
print(error) | ||
fatalError("Rendering error.") |
Copilot
AI
Sep 3, 2025
There was a problem hiding this comment.
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.
print(error) | |
fatalError("Rendering error.") | |
fatalError("Rendering error: \(error)") |
Copilot uses AI. Check for mistakes.
print("UI IMAGE CAST ERROR") | ||
fatalError("UIImage cast error.") |
Copilot
AI
Sep 3, 2025
There was a problem hiding this comment.
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.
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.
viewModel.$renderedFrame | ||
.sink { [weak self] image in | ||
self?.imageView.image = image | ||
} | ||
.store(in: &cancellables) |
Copilot
AI
Sep 3, 2025
There was a problem hiding this comment.
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.
Issue here -> #3
From a discussion between @tinyjin and @andyf-canva...
This PR introduces helper a SwiftUI
View
and UIKitUIView
to promote easier adoption of theLottieRenderer
-based rendering implementation.TODO: