-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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 on onAnimationReady
function support for delayed animation loading
#1802
Conversation
@calda Added tests that confirm both problem and workaround behavior. |
// MARK: Internal | ||
|
||
func test_dotLottieFile_hasAnimation_onInitialize() { | ||
XCTExpectFailure("This is expected failure due to loading delay") |
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.
[Note] This is the proof of the underlying issue.
Different from test_jsonFile_hasAnimation_onInitialize
, which is succeeding.
Thanks for the report -- I made changes in #1810 that I think resolve this issue, with a slightly different approach. |
e.g. you will be able to do: let animationView = LottieAnimationView(
dotLottieName: "DotLottie/animation",
completion: { animationView in
animationView.play()
}) |
Problem scope
Currently there is issue
play()
method getting called afterLottieAnimationView
has been initialized, butanimation
is not loaded yet for newly added.lottie
format, which needs file processing before animation is ready.there is currently no way to know when it is completed or way to properly handle it.
I propose solution that doesn't require complete rewrite of view lifecycle after changing to
.lottie
format.How to Reproduce
Simply create
LottieAnimationView
using any local.dotlottie
resource based initializer, bigger file size will guarantee the reproduction (30kb+). Key is to call play fast enough after calling the initializerYou can refer to added tests that can confirm the problem.
Proposed Solution
Until more proper alternative is found, I would like to suggest using functional method
onAnimationReady
that will return a closure with self (LottieAnimationView).This helps to keep code changes to minimum, and works similarly to all local and remote types.
It does not alter existing behavior, and works as convenient method for those who might need it.
Usage
Before:
After: