diff --git a/ios/Brushes/RNSVGBrushConverter.m b/ios/Brushes/RNSVGBrushConverter.m index 99af3103..146b6800 100644 --- a/ios/Brushes/RNSVGBrushConverter.m +++ b/ios/Brushes/RNSVGBrushConverter.m @@ -14,7 +14,7 @@ - (void)drawLinearGradient:(CGContextRef)context { - CGGradientRef gradient = CGGradientRetain([RCTConvert CGGradient:self.colors offset:0]); + CGGradientRef gradient = CGGradientRetain([RCTConvert RNSVGCGGradient:self.colors offset:0]); CGGradientDrawingOptions extendOptions = kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation; CGRect box = CGContextGetClipBoundingBox(context); @@ -25,10 +25,18 @@ float offsetX = (midX - width / 2); float offsetY = (midY - height / 2); - CGFloat x1 = [RNSVGPercentageConverter stringToFloat:(NSString *)[self.points objectAtIndex:0] relative:width offset:offsetX]; - CGFloat y1 = [RNSVGPercentageConverter stringToFloat:(NSString *)[self.points objectAtIndex:1] relative:height offset:offsetY]; - CGFloat x2 = [RNSVGPercentageConverter stringToFloat:(NSString *)[self.points objectAtIndex:2] relative:width offset:offsetX]; - CGFloat y2 = [RNSVGPercentageConverter stringToFloat:(NSString *)[self.points objectAtIndex:3] relative:height offset:offsetY]; + CGFloat x1 = [RNSVGPercentageConverter stringToFloat:(NSString *)[self.points objectAtIndex:0] + relative:width + offset:offsetX]; + CGFloat y1 = [RNSVGPercentageConverter stringToFloat:(NSString *)[self.points objectAtIndex:1] + relative:height + offset:offsetY]; + CGFloat x2 = [RNSVGPercentageConverter stringToFloat:(NSString *)[self.points objectAtIndex:2] + relative:width + offset:offsetX]; + CGFloat y2 = [RNSVGPercentageConverter stringToFloat:(NSString *)[self.points objectAtIndex:3] + relative:height + offset:offsetY]; CGContextDrawLinearGradient(context, gradient, CGPointMake(x1, y1), CGPointMake(x2, y2), extendOptions); CGGradientRelease(gradient); @@ -36,7 +44,7 @@ - (void)drawRidialGradient:(CGContextRef)context { - CGGradientRef gradient = CGGradientRetain([RCTConvert CGGradient:self.colors offset:0]); + CGGradientRef gradient = CGGradientRetain([RCTConvert RNSVGCGGradient:self.colors offset:0]); CGGradientDrawingOptions extendOptions = kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation; CGRect box = CGContextGetClipBoundingBox(context); @@ -47,12 +55,24 @@ float offsetX = (midX - width / 2); float offsetY = (midY - height / 2); - CGFloat rx = [RNSVGPercentageConverter stringToFloat:(NSString *)[_points objectAtIndex:2] relative:width offset:0]; - CGFloat ry = [RNSVGPercentageConverter stringToFloat:(NSString *)[_points objectAtIndex:3] relative:height offset:0]; - CGFloat fx = [RNSVGPercentageConverter stringToFloat:(NSString *)[_points objectAtIndex:0] relative:width offset:offsetX]; - CGFloat fy = [RNSVGPercentageConverter stringToFloat:(NSString *)[_points objectAtIndex:1] relative:height offset:offsetY] / (ry / rx); - CGFloat cx = [RNSVGPercentageConverter stringToFloat:(NSString *)[_points objectAtIndex:4] relative:width offset:offsetX]; - CGFloat cy = [RNSVGPercentageConverter stringToFloat:(NSString *)[_points objectAtIndex:5] relative:height offset:offsetY] / (ry / rx); + CGFloat rx = [RNSVGPercentageConverter stringToFloat:(NSString *)[self.points objectAtIndex:2] + relative:width + offset:0]; + CGFloat ry = [RNSVGPercentageConverter stringToFloat:(NSString *)[self.points objectAtIndex:3] + relative:height + offset:0]; + CGFloat fx = [RNSVGPercentageConverter stringToFloat:(NSString *)[self.points objectAtIndex:0] + relative:width + offset:offsetX]; + CGFloat fy = [RNSVGPercentageConverter stringToFloat:(NSString *)[self.points objectAtIndex:1] + relative:height + offset:offsetY] / (ry / rx); + CGFloat cx = [RNSVGPercentageConverter stringToFloat:(NSString *)[self.points objectAtIndex:4] + relative:width + offset:offsetX]; + CGFloat cy = [RNSVGPercentageConverter stringToFloat:(NSString *)[self.points objectAtIndex:5] + relative:height + offset:offsetY] / (ry / rx); CGAffineTransform transform = CGAffineTransformMakeScale(1, ry / rx); CGContextConcatCTM(context, transform); diff --git a/ios/Brushes/RNSVGPattern.m b/ios/Brushes/RNSVGPattern.m index 29cefdab..2a209723 100644 --- a/ios/Brushes/RNSVGPattern.m +++ b/ios/Brushes/RNSVGPattern.m @@ -26,7 +26,7 @@ return nil; } _image = CGImageRetain([RCTConvert CGImage:array[1]]); - _rect = [RCTConvert CGRect:array offset:2]; + _rect = [RCTConvert RNSVGCGRect:array offset:2]; } return self; } diff --git a/ios/Brushes/RNSVGSolidColorBrush.m b/ios/Brushes/RNSVGSolidColorBrush.m index 60ccbb2a..95aa5a44 100644 --- a/ios/Brushes/RNSVGSolidColorBrush.m +++ b/ios/Brushes/RNSVGSolidColorBrush.m @@ -19,7 +19,7 @@ - (instancetype)initWithArray:(NSArray *)array { if ((self = [super initWithArray:array])) { - _color = CGColorRetain([RCTConvert CGColor:array offset:1]); + _color = CGColorRetain([RCTConvert RNSVGCGColor:array offset:1]); } return self; } diff --git a/ios/Text/RNSVGTSpan.m b/ios/Text/RNSVGTSpan.m index 9cdad432..71903525 100644 --- a/ios/Text/RNSVGTSpan.m +++ b/ios/Text/RNSVGTSpan.m @@ -149,8 +149,7 @@ __block RNSVGBezierTransformer *bezierTransformer; [self traverseTextSuperviews:^(__kindof RNSVGText *node) { if ([node class] == [RNSVGTextPath class]) { - RNSVGTextPath *textPath = node; - bezierTransformer = [node getBezierTransformer]; + bezierTransformer = [(RNSVGTextPath*)node getBezierTransformer]; return NO; } return YES; @@ -170,7 +169,7 @@ break; } - targetView = [targetView superview]; + targetView = (RNSVGText*)[targetView superview]; result = block(targetView); } } diff --git a/ios/Utils/RCTConvert+RNSVG.h b/ios/Utils/RCTConvert+RNSVG.h index a180e720..41a4fd53 100644 --- a/ios/Utils/RCTConvert+RNSVG.h +++ b/ios/Utils/RCTConvert+RNSVG.h @@ -25,10 +25,9 @@ + (RNSVGVBMOS)RNSVGVBMOS:(id)json; + (RNSVGCGFloatArray)RNSVGCGFloatArray:(id)json; + (RNSVGBrush *)RNSVGBrush:(id)json; - -+ (RNSVGPathParser *)CGPath:(NSString *)d; -+ (CGRect)CGRect:(id)json offset:(NSUInteger)offset; -+ (CGColorRef)CGColor:(id)json offset:(NSUInteger)offset; -+ (CGGradientRef)CGGradient:(id)json offset:(NSUInteger)offset; ++ (RNSVGPathParser *)RNSVGCGPath:(NSString *)d; ++ (CGRect)RNSVGCGRect:(id)json offset:(NSUInteger)offset; ++ (CGColorRef)RNSVGCGColor:(id)json offset:(NSUInteger)offset; ++ (CGGradientRef)RNSVGCGGradient:(id)json offset:(NSUInteger)offset; @end diff --git a/ios/Utils/RCTConvert+RNSVG.m b/ios/Utils/RCTConvert+RNSVG.m index 2bc56773..b9cb0d50 100644 --- a/ios/Utils/RCTConvert+RNSVG.m +++ b/ios/Utils/RCTConvert+RNSVG.m @@ -18,11 +18,6 @@ @implementation RCTConvert (RNSVG) -+ (RNSVGPathParser *)CGPath:(NSString *)d -{ - return [[RNSVGPathParser alloc] initWithPathString: d]; -} - RCT_ENUM_CONVERTER(RNSVGCGFCRule, (@{ @"evenodd": @(kRNSVGCGFCRuleEvenodd), @"nonzero": @(kRNSVGCGFCRuleNonzero), @@ -80,64 +75,12 @@ RCT_ENUM_CONVERTER(RNSVGTextAnchor, (@{ } } -+ (NSArray *)RNSVGBezier:(id)json ++ (RNSVGPathParser *)RNSVGCGPath:(NSString *)d { - NSArray *arr = [self NSNumberArray:json]; - - NSMutableArray *beziers = [[NSMutableArray alloc] init]; - - NSUInteger count = [arr count]; - -#define NEXT_VALUE [self double:arr[i++]] - @try { - NSValue *startPoint = [NSValue valueWithCGPoint: CGPointMake(0, 0)]; - NSUInteger i = 0; - while (i < count) { - NSUInteger type = [arr[i++] unsignedIntegerValue]; - switch (type) { - case 0: - { - startPoint = [NSValue valueWithCGPoint: CGPointMake(NEXT_VALUE, NEXT_VALUE)]; - [beziers addObject: @[startPoint]]; - break; - } - case 1: - [beziers addObject: @[]]; - break; - case 2: - { - double x = NEXT_VALUE; - double y = NEXT_VALUE; - NSValue * destination = [NSValue valueWithCGPoint:CGPointMake(x, y)]; - [beziers addObject: @[ - destination, - startPoint, - destination - ]]; - break; - } - case 3: - [beziers addObject: @[ - [NSValue valueWithCGPoint:CGPointMake(NEXT_VALUE, NEXT_VALUE)], - [NSValue valueWithCGPoint:CGPointMake(NEXT_VALUE, NEXT_VALUE)], - [NSValue valueWithCGPoint:CGPointMake(NEXT_VALUE, NEXT_VALUE)], - ]]; - break; - default: - RCTLogError(@"Invalid RNSVGBezier type %zd at element %zd of %@", type, i, arr); - return nil; - } - } - } - @catch (NSException *exception) { - RCTLogError(@"Invalid RNSVGBezier format: %@", arr); - return nil; - } - - return beziers; + return [[RNSVGPathParser alloc] initWithPathString: d]; } -+ (CGRect)CGRect:(id)json offset:(NSUInteger)offset ++ (CGRect)RNSVGCGRect:(id)json offset:(NSUInteger)offset { NSArray *arr = [self NSArray:json]; if (arr.count < offset + 4) { @@ -150,7 +93,7 @@ RCT_ENUM_CONVERTER(RNSVGTextAnchor, (@{ }; } -+ (CGColorRef)CGColor:(id)json offset:(NSUInteger)offset ++ (CGColorRef)RNSVGCGColor:(id)json offset:(NSUInteger)offset { NSArray *arr = [self NSArray:json]; if (arr.count < offset + 4) { @@ -160,7 +103,7 @@ RCT_ENUM_CONVERTER(RNSVGTextAnchor, (@{ return [self CGColor:[arr subarrayWithRange:(NSRange){offset, 4}]]; } -+ (CGGradientRef)CGGradient:(id)json offset:(NSUInteger)offset ++ (CGGradientRef)RNSVGCGGradient:(id)json offset:(NSUInteger)offset { NSArray *arr = [self NSArray:json]; if (arr.count < offset) { diff --git a/ios/ViewManagers/RNSVGPathManager.m b/ios/ViewManagers/RNSVGPathManager.m index 97d7439d..ae4648dc 100644 --- a/ios/ViewManagers/RNSVGPathManager.m +++ b/ios/ViewManagers/RNSVGPathManager.m @@ -20,6 +20,6 @@ RCT_EXPORT_MODULE() return [RNSVGPath new]; } -RCT_EXPORT_VIEW_PROPERTY(d, CGPath) +RCT_EXPORT_VIEW_PROPERTY(d, RNSVGCGPath) @end