Skip to content
This repository has been archived by the owner on Mar 21, 2022. It is now read-only.

Commit

Permalink
fix: handling of gradients without stops
Browse files Browse the repository at this point in the history
  • Loading branch information
msand committed Sep 27, 2019
1 parent c12d66e commit 18828c0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 7 additions & 2 deletions android/src/main/java/com/horcrux/svg/Brush.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,12 @@ void setupPaint(Paint paint, RectF pathBoundingBox, float scale, float opacity)
return;
}

int stopsCount = mColors.size() / 2;
int size = mColors.size();
if (size == 0) {
FLog.w(ReactConstants.TAG, "Gradient contains no stops");
return;
}
int stopsCount = size / 2;
int[] stopsColors = new int[stopsCount];
float[] stops = new float[stopsCount];
parseGradientStops(mColors, stopsCount, stops, stopsColors, opacity);
Expand All @@ -167,7 +172,7 @@ void setupPaint(Paint paint, RectF pathBoundingBox, float scale, float opacity)
// editors or other tools, so let's handle that gracefully.
stopsColors = new int[] { stopsColors[0], stopsColors[0] };
stops = new float[] { stops[0], stops[0] };
FLog.w(ReactConstants.TAG, "Gradient contains only on stop");
FLog.w(ReactConstants.TAG, "Gradient contains only one stop");
}

if (mType == BrushType.LINEAR_GRADIENT) {
Expand Down
8 changes: 8 additions & 0 deletions ios/Brushes/RNSVGPainter.m
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ - (void)paintPattern:(CGContextRef)context bounds:(CGRect)bounds

- (void)paintLinearGradient:(CGContextRef)context bounds:(CGRect)bounds
{
if ([_colors count] == 0) {
RCTLogWarn(@"No stops in gradient");
return;
}
CGGradientRef gradient = CGGradientRetain([RCTConvert RNSVGCGGradient:_colors]);
CGGradientDrawingOptions extendOptions = kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation;

Expand All @@ -208,6 +212,10 @@ - (void)paintLinearGradient:(CGContextRef)context bounds:(CGRect)bounds

- (void)paintRadialGradient:(CGContextRef)context bounds:(CGRect)bounds
{
if ([_colors count] == 0) {
RCTLogWarn(@"No stops in gradient");
return;
}
CGGradientRef gradient = CGGradientRetain([RCTConvert RNSVGCGGradient:_colors]);
CGGradientDrawingOptions extendOptions = kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation;

Expand Down

0 comments on commit 18828c0

Please sign in to comment.