diff --git a/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java b/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java index 67d50c341d..42f83459c8 100644 --- a/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java +++ b/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java @@ -1021,6 +1021,13 @@ public List resolveKeyPath(KeyPath keyPath) { return lottieDrawable.resolveKeyPath(keyPath); } + /** + * Clear the value callback for all nodes that match the given {@link KeyPath} and property. + */ + public void clearValueCallback(KeyPath keyPath, T property) { + lottieDrawable.addValueCallback(keyPath, property, (LottieValueCallback) null); + } + /** * Add a property callback for the specified {@link KeyPath}. This {@link KeyPath} can resolve * to multiple contents. In that case, the callback's value will apply to all of them. diff --git a/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java b/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java index abf094f56b..5e9050eb03 100644 --- a/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java +++ b/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java @@ -1288,6 +1288,8 @@ public List resolveKeyPath(KeyPath keyPath) { *

* Internally, this will check if the {@link KeyPath} has already been resolved with * {@link #resolveKeyPath(KeyPath)} and will resolve it if it hasn't. + * + * Set the callback to null to clear it. */ public void addValueCallback( final KeyPath keyPath, final T property, @Nullable final LottieValueCallback callback) { diff --git a/lottie/src/main/java/com/airbnb/lottie/model/layer/SolidLayer.java b/lottie/src/main/java/com/airbnb/lottie/model/layer/SolidLayer.java index 993e1b3a42..65ae32c126 100644 --- a/lottie/src/main/java/com/airbnb/lottie/model/layer/SolidLayer.java +++ b/lottie/src/main/java/com/airbnb/lottie/model/layer/SolidLayer.java @@ -24,6 +24,7 @@ public class SolidLayer extends BaseLayer { private final Path path = new Path(); private final Layer layerModel; @Nullable private BaseKeyframeAnimation colorFilterAnimation; + @Nullable private BaseKeyframeAnimation colorAnimation; SolidLayer(LottieDrawable lottieDrawable, Layer layerModel) { super(lottieDrawable, layerModel); @@ -43,6 +44,9 @@ public class SolidLayer extends BaseLayer { int opacity = transform.getOpacity() == null ? 100 : transform.getOpacity().getValue(); int alpha = (int) (parentAlpha / 255f * (backgroundAlpha / 255f * opacity / 100f) * 255); paint.setAlpha(alpha); + if (colorAnimation != null) { + paint.setColor(colorAnimation.getValue()); + } if (colorFilterAnimation != null) { paint.setColorFilter(colorFilterAnimation.getValue()); } @@ -88,6 +92,13 @@ public void addValueCallback(T property, @Nullable LottieValueCallback ca colorFilterAnimation = new ValueCallbackKeyframeAnimation<>((LottieValueCallback) callback); } + } else if (property == LottieProperty.COLOR) { + if (callback == null) { + colorAnimation = null; + paint.setColor(layerModel.getSolidColor()); + } else { + colorAnimation = new ValueCallbackKeyframeAnimation<>((LottieValueCallback) callback); + } } } } diff --git a/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/tests/DynamicPropertiesTestCase.kt b/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/tests/DynamicPropertiesTestCase.kt index fd7d915146..407e3ea105 100644 --- a/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/tests/DynamicPropertiesTestCase.kt +++ b/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/tests/DynamicPropertiesTestCase.kt @@ -377,6 +377,14 @@ class DynamicPropertiesTestCase : SnapshotTestCase { assetName = "Tests/AnimatedShadow.json" ) + testDynamicProperty( + "Solid Color", + KeyPath("Cyan Solid 1", "**"), + LottieProperty.COLOR, + LottieValueCallback(Color.YELLOW), + assetName = "Tests/SolidLayerTransform.json" + ) + withDrawable("Tests/DynamicGradient.json", "Gradient Colors", "Linear Gradient Fill") { drawable -> val value = object : LottieValueCallback>() { override fun getValue(frameInfo: LottieFrameInfo>?): Array { @@ -483,4 +491,4 @@ class DynamicPropertiesTestCase : SnapshotTestCase { drawable.progress = progress } } -} \ No newline at end of file +}