Skip to content

Commit

Permalink
Allow targeting mattes with KeyPaths (#1710)
Browse files Browse the repository at this point in the history
Fixes #974
  • Loading branch information
gpeal authored Dec 27, 2020
1 parent 4ff1ebb commit 7d8b5de
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private boolean hasTwoOrMoreDrawableContent() {

@Override public void resolveKeyPath(
KeyPath keyPath, int depth, List<KeyPath> accumulator, KeyPath currentPartialKeyPath) {
if (!keyPath.matches(getName(), depth)) {
if (!keyPath.matches(getName(), depth) && !"__container".equals(getName())) {
return;
}

Expand Down
12 changes: 12 additions & 0 deletions lottie/src/main/java/com/airbnb/lottie/model/layer/BaseLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,18 @@ public void setContents(List<Content> contentsBefore, List<Content> contentsAfte
@Override
public void resolveKeyPath(
KeyPath keyPath, int depth, List<KeyPath> accumulator, KeyPath currentPartialKeyPath) {
if (matteLayer != null) {
KeyPath matteCurrentPartialKeyPath = currentPartialKeyPath.addKey(matteLayer.getName());
if (keyPath.fullyResolvesTo(matteLayer.getName(), depth)) {
accumulator.add(matteCurrentPartialKeyPath.resolve(matteLayer));
}

if (keyPath.propagateToChildren(getName(), depth)) {
int newDepth = depth + keyPath.incrementDepthBy(matteLayer.getName(), depth);
matteLayer.resolveChildKeyPath(keyPath, newDepth, accumulator, matteCurrentPartialKeyPath);
}
}

if (!keyPath.matches(getName(), depth)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,11 @@ class LottieTest {
{ ScaleXY(-1.0f, 1.0f) })
}

withDrawable("Tests/TrackMattes.json", "Matte", "Matte property") { drawable ->
val keyPath = KeyPath("Shape Layer 1", "Rectangle 1", "Rectangle Path 1")
drawable.addValueCallback(keyPath, LottieProperty.RECTANGLE_SIZE, LottieValueCallback(PointF(50f, 50f)))
}

withDrawable("Tests/Text.json", "Text", "Text Fill (Blue -> Green)") { drawable ->
val value = object : LottieValueCallback<Int>() {
override fun getValue(frameInfo: LottieFrameInfo<Int>?) = Color.GREEN
Expand Down

0 comments on commit 7d8b5de

Please sign in to comment.