Skip to content

Commit

Permalink
fix(ios): optimize extractPathData, clear PathMeasure when no textPath
Browse files Browse the repository at this point in the history
Return early if calling extractPathData with same CGPath as previously
  • Loading branch information
msand committed Oct 4, 2019
1 parent 2c57af2 commit df69c26
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
6 changes: 5 additions & 1 deletion ios/Text/RNSVGTSpan.m
Original file line number Diff line number Diff line change
Expand Up @@ -1032,18 +1032,22 @@ - (void)setupTextPath:(CGContextRef)context
{
textPath = nil;
RNSVGText *parent = (RNSVGText*)[self superview];
CGPathRef path;
while (parent) {
if ([parent class] == [RNSVGTextPath class]) {
textPath = (RNSVGTextPath*) parent;
RNSVGNode *template = [self.svgView getDefinedTemplate:textPath.href];
CGPathRef path = [template getPath:nil];
path = [template getPath:context];
[measure extractPathData:path];
break;
} else if (![parent isKindOfClass:[RNSVGText class]]) {
break;
}
parent = (RNSVGText*)[parent superview];
}
if (!path) {
[measure reset];
}
}

@end
3 changes: 2 additions & 1 deletion ios/Utils/RNSVGPathMeasure.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
@interface RNSVGPathMeasure : NSObject

@property CGFloat pathLength;
@property CGPathRef textPath;
@property CGPathRef path;
@property NSMutableArray *lengths;
@property NSMutableArray *lines;
@property NSUInteger lineCount;
@property BOOL isClosed;

- (void)reset;
- (void)extractPathData:(CGPathRef)path;
- (void)getPosAndTan:(CGFloat *)angle midPoint:(CGFloat)midPoint px:(CGFloat *)px py:(CGFloat *)py;

Expand Down
13 changes: 13 additions & 0 deletions ios/Utils/RNSVGPathMeasure.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,20 @@ - (void)addLine:(CGPoint *)last next:(const CGPoint *)next {
*last = *next;
}

- (void)reset {
_lengths = nil;
_lines = nil;
_isClosed = NO;
_lineCount = 0;
_pathLength = 0;
_path = nil;
}

- (void)extractPathData:(CGPathRef)path {
if (path == _path) {
return;
}
_path = path;
CGPoint origin = CGPointMake (0.0, 0.0);
CGPoint last = CGPointMake (0.0, 0.0);
_lengths = [NSMutableArray array];
Expand Down

0 comments on commit df69c26

Please sign in to comment.