Ensure ImageView updates Drawable bounds when not using LottieAnimationView (#1504)
Fixes #1492
diff --git a/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java b/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java
index 0102049..fd1c95d 100644
--- a/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java
+++ b/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java
@@ -502,11 +502,6 @@
return;
}
- // If you set a different composition on the view, the bounds will not update unless
- // the drawable is different than the original.
- setImageDrawable(null);
- setImageDrawable(lottieDrawable);
-
// This is needed to makes sure that the animation is properly played/paused for the current visibility state.
// It is possible that the drawable had a lazy composition task to play the animation but this view subsequently
// became invisible. Comment this out and run the espresso tests to see a failing test.
diff --git a/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java b/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java
index 15af03f..70fa4af 100644
--- a/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java
+++ b/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java
@@ -231,6 +231,14 @@
composition.setPerformanceTrackingEnabled(performanceTrackingEnabled);
+ // Ensure that ImageView updates the drawable width/height so it can
+ // properly calculate its drawable matrix.
+ Callback callback = getCallback();
+ if (callback instanceof ImageView) {
+ ((ImageView) callback).setImageDrawable(null);
+ ((ImageView) callback).setImageDrawable(this);
+ }
+
return true;
}