Skip to content

Commit

Permalink
Add COMPOSITION in KeyPath to target root composition layer. (#1559)
Browse files Browse the repository at this point in the history
  • Loading branch information
boduan-coder authored May 29, 2020
1 parent 848a86c commit b7bd15c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,14 @@ class LottieTest {
drawable.addValueCallback(KeyPath("Linear", "Rectangle", "Gradient Fill"), LottieProperty.OPACITY, value)
}

withDrawable("Tests/MatteTimeStretchScan.json", "Mirror animation", "Mirror animation") {
drawable ->
drawable.addValueCallback(KeyPath.COMPOSITION, LottieProperty.TRANSFORM_ANCHOR_POINT,
{ PointF(drawable.bounds.width().toFloat(), 0f) })
drawable.addValueCallback(KeyPath.COMPOSITION, LottieProperty.TRANSFORM_SCALE,
{ ScaleXY(-1.0f, 1.0f) })
}

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
5 changes: 4 additions & 1 deletion lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,10 @@ public void run(LottieComposition composition) {
return;
}
boolean invalidate;
if (keyPath.getResolvedElement() != null) {
if (keyPath == KeyPath.COMPOSITION) {
compositionLayer.addValueCallback(property, callback);
invalidate = true;
} else if (keyPath.getResolvedElement() != null) {
keyPath.getResolvedElement().addValueCallback(property, callback);
invalidate = true;
} else {
Expand Down
10 changes: 9 additions & 1 deletion lottie/src/main/java/com/airbnb/lottie/model/KeyPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
/**
* Defines which content to target.
* The keypath can contain wildcards ('*') with match exactly 1 item.
* or globstars ('**') which match 0 or more items.
* or globstars ('**') which match 0 or more items. or KeyPath.COMPOSITION
* to represent the root composition layer.
*
* For example, if your content were arranged like this:
* Gabriel (Shape Layer)
Expand All @@ -35,12 +36,19 @@
* new KeyPath("*", "Body", Left Hand", "Fill");
* Match anything with the name Fill:
* new KeyPath("**", "Fill");
* Target the the root composition layer:
* KeyPath.COMPOSITION
*
*
* NOTE: Content that are part of merge paths or repeaters cannot currently be resolved with
* a {@link KeyPath}. This may be fixed in the future.
*/
public class KeyPath {
/**
* A singleton KeyPath that targets on the root composition layer.
* This is useful if you want to apply transformer to the animation as a whole.
*/
public final static KeyPath COMPOSITION = new KeyPath("COMPOSITION");

private final List<String> keys;
@Nullable private KeyPathElement resolvedElement;
Expand Down

0 comments on commit b7bd15c

Please sign in to comment.