Skip to content

Commit ac2599c

Browse files
authored
Fix radial gradient crash (#2611)
Fixes #2610
1 parent 7fff42b commit ac2599c

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lottie/src/main/java/com/airbnb/lottie/animation/content/GradientFillContent.java

+17-1
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,14 @@ private LinearGradient getLinearGradient() {
193193
GradientColor gradientColor = colorAnimation.getValue();
194194
int[] colors = applyDynamicColorsIfNeeded(gradientColor.getColors());
195195
float[] positions = gradientColor.getPositions();
196+
197+
// Add check for minimum colors
198+
if (colors.length < 2) {
199+
// If only one color, duplicate it to create a solid color gradient
200+
colors = new int[]{colors[0], colors[0]};
201+
positions = new float[]{0f, 1f};
202+
}
203+
196204
gradient = new LinearGradient(startPoint.x, startPoint.y, endPoint.x, endPoint.y, colors,
197205
positions, Shader.TileMode.CLAMP);
198206
linearGradientCache.put(gradientHash, gradient);
@@ -210,13 +218,21 @@ private RadialGradient getRadialGradient() {
210218
GradientColor gradientColor = colorAnimation.getValue();
211219
int[] colors = applyDynamicColorsIfNeeded(gradientColor.getColors());
212220
float[] positions = gradientColor.getPositions();
221+
222+
// Add check for minimum colors
223+
if (colors.length < 2) {
224+
// If only one color, duplicate it to create a solid color gradient
225+
colors = new int[]{colors[0], colors[0]};
226+
positions = new float[]{0f, 1f};
227+
}
228+
213229
float x0 = startPoint.x;
214230
float y0 = startPoint.y;
215231
float x1 = endPoint.x;
216232
float y1 = endPoint.y;
217233
float r = (float) Math.hypot(x1 - x0, y1 - y0);
218234
if (r <= 0) {
219-
r = 0.001f;
235+
r = 0.001f;
220236
}
221237
gradient = new RadialGradient(x0, y0, r, colors, positions, Shader.TileMode.CLAMP);
222238
radialGradientCache.put(gradientHash, gradient);

snapshot-tests/src/main/assets/Tests/RadialGradent.json

+1
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)