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

LottieAnimationView.duration returns 0 #2481

Closed
u13 opened this issue Mar 14, 2024 · 3 comments
Closed

LottieAnimationView.duration returns 0 #2481

u13 opened this issue Mar 14, 2024 · 3 comments

Comments

@u13
Copy link

u13 commented Mar 14, 2024

binding.lottieAnimation.setAnimation(fileName)
val animationDuration = binding.lottieAnimation.duration

// animationDuration == 0

If we go inside of LottieAnimationView, we see that:

  public long getDuration() {
    LottieComposition composition = getComposition(); // composition == null
    return composition != null ? (long) composition.getDuration() : 0;
  }

and composition == null because:

  @Nullable public LottieComposition getComposition() {
    return getDrawable() == lottieDrawable ? lottieDrawable.getComposition() : null; // getDrawable() == null
  }

Most probably this bug appeared after merging this PR #2468

@gpeal
Copy link
Collaborator

gpeal commented Mar 14, 2024

Did you set your own drawable on LottieAnimationView (like your own resource or something)?

@u13
Copy link
Author

u13 commented Mar 14, 2024

Did you set your own drawable on LottieAnimationView (like your own resource or something)?

No, it's just:

    <com.airbnb.lottie.LottieAnimationView
        android:id="@+id/lottie_animation"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center" />

@gpeal
Copy link
Collaborator

gpeal commented Apr 1, 2024

Lottie parses compositions synchronously. If you are setting an animation for the first time, the duration won't be synchronously available. I just did a test where I logged the duration in the callback for LottieAnimationView.addLottieOnCompositionLoadedListener and it returned the correct duration.

@gpeal gpeal closed this as completed Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants