Fix rotations on solid layers (#598)
Prior to this, the transform matrix got mapped to a solid layer's bounds. However, if there is a rotation then the final shape won't be a rect so we need to map the points instead.
Fixes #587
diff --git a/LottieSample/src/main/assets/Tests/SolidLayerTransform.json b/LottieSample/src/main/assets/Tests/SolidLayerTransform.json
new file mode 100644
index 0000000..71a7962
--- /dev/null
+++ b/LottieSample/src/main/assets/Tests/SolidLayerTransform.json
@@ -0,0 +1 @@
+{"v":"4.11.1","fr":29.9700012207031,"ip":0,"op":61.0000024845809,"w":300,"h":300,"nm":"SolidRotation","ddd":0,"assets":[],"layers":[{"ddd":0,"ind":1,"ty":1,"nm":"Cyan Solid 1","sr":1,"ks":{"o":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":0,"s":[100],"e":[50]},{"t":60.0000024438501}],"ix":11},"r":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":0,"s":[0],"e":[180]},{"t":60.0000024438501}],"ix":10},"p":{"a":1,"k":[{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":0,"s":[150,150,0],"e":[275,275,0],"to":[20.8333339691162,20.8333339691162,0],"ti":[-20.8333339691162,-20.8333339691162,0]},{"t":60.0000024438501}],"ix":2},"a":{"a":1,"k":[{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":0,"s":[150,150,0],"e":[50,50,0],"to":[-16.6666660308838,-16.6666660308838,0],"ti":[16.6666660308838,16.6666660308838,0]},{"t":60.0000024438501}],"ix":1},"s":{"a":1,"k":[{"i":{"x":[0.833,0.833,0.833],"y":[0.833,0.833,0.833]},"o":{"x":[0.167,0.167,0.167],"y":[0.167,0.167,0.167]},"n":["0p833_0p833_0p167_0p167","0p833_0p833_0p167_0p167","0p833_0p833_0p167_0p167"],"t":0,"s":[100,100,100],"e":[50,50,100]},{"t":60.0000024438501}],"ix":6}},"ao":0,"sw":100,"sh":100,"sc":"#00ffff","ip":0,"op":61.0000024845809,"st":0,"bm":0}]}
\ No newline at end of file
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 4a79a06..7696fb3 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
@@ -5,6 +5,7 @@
import android.graphics.ColorFilter;
import android.graphics.Matrix;
import android.graphics.Paint;
+import android.graphics.Path;
import android.graphics.RectF;
import android.support.annotation.Nullable;
@@ -18,6 +19,8 @@
private final RectF rect = new RectF();
private final Paint paint = new Paint();
+ private final float[] points = new float[8];
+ private final Path path = new Path();
private final Layer layerModel;
@Nullable private BaseKeyframeAnimation<ColorFilter, ColorFilter> colorFilterAnimation;
@@ -42,20 +45,34 @@
paint.setColorFilter(colorFilterAnimation.getValue());
}
if (alpha > 0) {
- updateRect(parentMatrix);
- canvas.drawRect(rect, paint);
+ points[0] = 0;
+ points[1] = 0;
+ points[2] = layerModel.getSolidWidth();
+ points[3] = 0;
+ points[4] = layerModel.getSolidWidth();
+ points[5] = layerModel.getSolidHeight();
+ points[6] = 0;
+ points[7] = layerModel.getSolidHeight();
+
+ // We can't map rect here because if there is rotation on the transform then we aren't
+ // actually drawing a rect.
+ parentMatrix.mapPoints(points);
+ path.reset();
+ path.moveTo(points[0], points[1]);
+ path.lineTo(points[2], points[3]);
+ path.lineTo(points[4], points[5]);
+ path.lineTo(points[6], points[7]);
+ path.lineTo(points[0], points[1]);
+ path.close();
+ canvas.drawPath(path, paint);
}
}
@Override public void getBounds(RectF outBounds, Matrix parentMatrix) {
super.getBounds(outBounds, parentMatrix);
- updateRect(boundsMatrix);
- outBounds.set(rect);
- }
-
- private void updateRect(Matrix matrix) {
rect.set(0, 0, layerModel.getSolidWidth(), layerModel.getSolidHeight());
- matrix.mapRect(rect);
+ boundsMatrix.mapRect(rect);
+ outBounds.set(rect);
}
@SuppressWarnings("unchecked")