Fix issue where animation size could be incorrect after loading async animation by calda · Pull Request #2379 · airbnb/lottie-ios

This PR fixes an issue where the view's size could be incorrect after loading an async animation.

I believe this issue was introduced by #2289, when we changed the lifecycle of the LottieAnimationView. Previously it was only added to the view hierarchy after the animation finished loading. Now it's always present, so can have an intrinsic size of zero if measured before the async animation finishes loading.

Here's the sample code I added to test this case. The async case was broken before. Now both work as expected.

VStack {
  LottieView(animation: .named("Samples/LottieLogo1"))
    .intrinsicSize()
    .looping()

  Text("intrinsic size")
}

VStack {
  LottieView {
    try await Task.sleep(for: .seconds(1))
    return LottieAnimation.named("Samples/LottieLogo1")
  }
  .intrinsicSize()
  .looping()

  Text("intrinsic size, async")
}

Before

Screenshot 2024-04-15 at 12 09 25 PM

After

Screenshot 2024-04-15 at 12 09 50 PM