Skip to content

Commit

Permalink
Handle null color callbacks in SolidLayer (airbnb#2434)
Browse files Browse the repository at this point in the history
  • Loading branch information
gpeal authored Dec 27, 2023
1 parent 94eabb9 commit e85787b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.airbnb.lottie.value.LottieValueCallback;

public class SolidLayer extends BaseLayer {

private final RectF rect = new RectF();
private final Paint paint = new LPaint();
private final float[] points = new float[8];
Expand All @@ -41,12 +42,17 @@ public class SolidLayer extends BaseLayer {
return;
}

Integer color = colorAnimation == null ? null : colorAnimation.getValue();
if (color != null) {
paint.setColor(color);
} else {
paint.setColor(layerModel.getSolidColor());
}

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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,14 @@ class DynamicPropertiesTestCase : SnapshotTestCase {
assetName = "Tests/SolidLayerTransform.json"
)

testDynamicProperty(
"Solid Color w/ null",
KeyPath("Cyan Solid 1", "**"),
LottieProperty.COLOR,
LottieValueCallback(null),
assetName = "Tests/SolidLayerTransform.json"
)

withDrawable("Tests/DynamicGradient.json", "Gradient Colors", "Linear Gradient Fill") { drawable ->
val value = object : LottieValueCallback<Array<Int>>() {
override fun getValue(frameInfo: LottieFrameInfo<Array<Int>>?): Array<Int> {
Expand Down

0 comments on commit e85787b

Please sign in to comment.