Check for lottieDrawable in some ImageView methods
Fixes #159
diff --git a/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java b/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java
index b71a126..3e0369d 100644
--- a/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java
+++ b/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java
@@ -119,10 +119,24 @@
}
}
+ @Override public void setImageResource(int resId) {
+ super.setImageResource(resId);
+ recycleBitmaps();
+ }
+
+ @Override public void setImageDrawable(Drawable drawable) {
+ if (drawable != lottieDrawable) {
+ recycleBitmaps();
+ }
+ super.setImageDrawable(drawable);
+ }
+
@Override public void invalidateDrawable(Drawable dr) {
- // We always want to invalidate the root drawable to it redraws the whole drawable.
- // Eventually it would be great to be able to invalidate just the changed region.
- super.invalidateDrawable(lottieDrawable);
+ if (getDrawable() == lottieDrawable) {
+ // We always want to invalidate the root drawable to it redraws the whole drawable.
+ // Eventually it would be great to be able to invalidate just the changed region.
+ super.invalidateDrawable(lottieDrawable);
+ }
}
@Override protected Parcelable onSaveInstanceState() {