Skip to content

Commit df69c26

Browse files
committed
fix(ios): optimize extractPathData, clear PathMeasure when no textPath
Return early if calling extractPathData with same CGPath as previously
1 parent 2c57af2 commit df69c26

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

ios/Text/RNSVGTSpan.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,18 +1032,22 @@ - (void)setupTextPath:(CGContextRef)context
10321032
{
10331033
textPath = nil;
10341034
RNSVGText *parent = (RNSVGText*)[self superview];
1035+
CGPathRef path;
10351036
while (parent) {
10361037
if ([parent class] == [RNSVGTextPath class]) {
10371038
textPath = (RNSVGTextPath*) parent;
10381039
RNSVGNode *template = [self.svgView getDefinedTemplate:textPath.href];
1039-
CGPathRef path = [template getPath:nil];
1040+
path = [template getPath:context];
10401041
[measure extractPathData:path];
10411042
break;
10421043
} else if (![parent isKindOfClass:[RNSVGText class]]) {
10431044
break;
10441045
}
10451046
parent = (RNSVGText*)[parent superview];
10461047
}
1048+
if (!path) {
1049+
[measure reset];
1050+
}
10471051
}
10481052

10491053
@end

ios/Utils/RNSVGPathMeasure.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
@interface RNSVGPathMeasure : NSObject
1212

1313
@property CGFloat pathLength;
14-
@property CGPathRef textPath;
14+
@property CGPathRef path;
1515
@property NSMutableArray *lengths;
1616
@property NSMutableArray *lines;
1717
@property NSUInteger lineCount;
1818
@property BOOL isClosed;
1919

20+
- (void)reset;
2021
- (void)extractPathData:(CGPathRef)path;
2122
- (void)getPosAndTan:(CGFloat *)angle midPoint:(CGFloat)midPoint px:(CGFloat *)px py:(CGFloat *)py;
2223

ios/Utils/RNSVGPathMeasure.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,20 @@ - (void)addLine:(CGPoint *)last next:(const CGPoint *)next {
9494
*last = *next;
9595
}
9696

97+
- (void)reset {
98+
_lengths = nil;
99+
_lines = nil;
100+
_isClosed = NO;
101+
_lineCount = 0;
102+
_pathLength = 0;
103+
_path = nil;
104+
}
105+
97106
- (void)extractPathData:(CGPathRef)path {
107+
if (path == _path) {
108+
return;
109+
}
110+
_path = path;
98111
CGPoint origin = CGPointMake (0.0, 0.0);
99112
CGPoint last = CGPointMake (0.0, 0.0);
100113
_lengths = [NSMutableArray array];

0 commit comments

Comments
 (0)