From d0c49c98d3c68c4ffe1fdf7d551d9866374c540c Mon Sep 17 00:00:00 2001 From: Gabriel Peal Date: Fri, 11 Nov 2022 19:38:43 -0800 Subject: [PATCH] Allow repeater contents to have dynamic properties --- .../lottie/animation/content/ContentGroup.java | 4 ++++ .../lottie/animation/content/RepeaterContent.java | 6 ++++++ .../snapshots/tests/DynamicPropertiesTestCase.kt | 14 ++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/lottie/src/main/java/com/airbnb/lottie/animation/content/ContentGroup.java b/lottie/src/main/java/com/airbnb/lottie/animation/content/ContentGroup.java index 1db7f55d0e..2a9bf95a4c 100644 --- a/lottie/src/main/java/com/airbnb/lottie/animation/content/ContentGroup.java +++ b/lottie/src/main/java/com/airbnb/lottie/animation/content/ContentGroup.java @@ -115,6 +115,10 @@ public ContentGroup(final LottieDrawable lottieDrawable, BaseLayer layer, ShapeG } } + public List getContents() { + return contents; + } + List getPathList() { if (pathContents == null) { pathContents = new ArrayList<>(); diff --git a/lottie/src/main/java/com/airbnb/lottie/animation/content/RepeaterContent.java b/lottie/src/main/java/com/airbnb/lottie/animation/content/RepeaterContent.java index 8b6d122679..4a721fb5ee 100644 --- a/lottie/src/main/java/com/airbnb/lottie/animation/content/RepeaterContent.java +++ b/lottie/src/main/java/com/airbnb/lottie/animation/content/RepeaterContent.java @@ -131,6 +131,12 @@ public RepeaterContent(LottieDrawable lottieDrawable, BaseLayer layer, Repeater @Override public void resolveKeyPath( KeyPath keyPath, int depth, List accumulator, KeyPath currentPartialKeyPath) { MiscUtils.resolveKeyPath(keyPath, depth, accumulator, currentPartialKeyPath, this); + for (int i = 0; i < contentGroup.getContents().size(); i++) { + Content content = contentGroup.getContents().get(i); + if (content instanceof KeyPathElementContent) { + MiscUtils.resolveKeyPath(keyPath, depth, accumulator, currentPartialKeyPath, (KeyPathElementContent) content); + } + } } @SuppressWarnings("unchecked") 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 f6fa19aa51..fd7d915146 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 @@ -250,6 +250,20 @@ class DynamicPropertiesTestCase : SnapshotTestCase { LottieRelativePointValueCallback(PointF(100f, 100f)) ) + testDynamicProperty( + "Repeater contents", + KeyPath("Shape Layer 1", "Repeater Shape", "Repeater 1"), + LottieProperty.TRANSFORM_POSITION, + LottieRelativePointValueCallback(PointF(100f, 100f)) + ) + + testDynamicProperty( + "Repeater sub-contents", + KeyPath("Shape Layer 1", "Repeater Shape", "Fill 1"), + LottieProperty.COLOR_FILTER, + LottieValueCallback(SimpleColorFilter(Color.GREEN)) + ) + testDynamicProperty( "Repeater transform start opacity", KeyPath("Shape Layer 1", "Repeater Shape", "Repeater 1"),