fix: radialGradient r={0} (#2271)

# Summary

* Fixed crash on Android when `<RadialGradient r={0}>`.
* Fixed render issue on Android and iOS when radius is zero. According
to [MDN
Docs](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/r#radialgradient)
> A value of lower or equal to zero will cause the area to be painted as
a single color using the color and opacity of the last gradient
`<stop>`.

## Test Plan

Test is available in `TestsExample` as `Test2170`

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| iOS     |        |
| Android |        |


Fixes #2170
This commit is contained in:
Jakub Grzywacz
2024-05-15 12:00:52 +02:00
committed by GitHub
parent 19b2e42e1b
commit 38a8dbca39
3 changed files with 82 additions and 0 deletions
+9
View File
@@ -232,6 +232,15 @@ void PatternFunction(void *info, CGContextRef context)
CGFloat rx = [self getVal:[_points objectAtIndex:2] relative:width];
CGFloat ry = [self getVal:[_points objectAtIndex:3] relative:height];
if (rx <= 0 || ry <= 0) {
// Gradient with radius = 0 should be rendered as solid color of the last stop
rx = width;
ry = height;
CGGradientRelease(gradient);
NSArray<NSNumber *> *gradientArray = @[_colors.firstObject, _colors.lastObject, _colors[_colors.count-2], _colors.lastObject];
gradient = CGGradientRetain([RCTConvert RNSVGCGGradient:gradientArray]);
}
double ratio = ry / rx;
CGFloat fx = [self getVal:[_points objectAtIndex:0] relative:width] + offsetX;