Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle null color callbacks in SolidLayer #2434

Merged
merged 2 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading