mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-01 22:25:12 +00:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user