[ios] Simplify strokeDashArray implementation

This commit is contained in:
Mikael Sand
2018-10-20 03:03:23 +03:00
parent e576813329
commit 5693b9e9bd
2 changed files with 12 additions and 18 deletions
-1
View File
@@ -26,7 +26,6 @@
@property (nonatomic, assign) CGLineCap strokeLinecap;
@property (nonatomic, assign) CGLineJoin strokeLinejoin;
@property (nonatomic, assign) CGFloat strokeMiterlimit;
@property (nonatomic, assign) RNSVGCGFloatArray strokeDasharrayData;
@property (nonatomic, strong) NSArray<RNSVGLength *> *strokeDasharray;
@property (nonatomic, assign) CGFloat strokeDashoffset;
@property (nonatomic, copy) NSArray<NSString *> *propList;
+12 -17
View File
@@ -17,6 +17,7 @@
NSArray<NSString *> *_lastMergedList;
NSArray<NSString *> *_attributeList;
NSArray<RNSVGLength *> *_sourceStrokeDashArray;
CGFloat *_strokeDashArrayData;
CGPathRef _strokePath;
CGPathRef _hitArea;
}
@@ -153,9 +154,10 @@
CGPathRelease(_hitArea);
CGPathRelease(_strokePath);
_sourceStrokeDashArray = nil;
if (_strokeDasharrayData.array) {
free(_strokeDasharrayData.array);
if (_strokeDashArrayData) {
free(_strokeDashArrayData);
}
_strokeDashArrayData = nil;
}
@@ -325,27 +327,20 @@ UInt32 saturate(double value) {
CGContextSetLineCap(context, self.strokeLinecap);
CGContextSetLineJoin(context, self.strokeLinejoin);
NSArray<RNSVGLength *>* strokeDasharray = self.strokeDasharray;
NSUInteger count = strokeDasharray.count;
if (strokeDasharray.count) {
RNSVGCGFloatArray dash = _strokeDasharrayData;
if (count) {
if (strokeDasharray != _sourceStrokeDashArray) {
_sourceStrokeDashArray = strokeDasharray;
if (dash.array) {
free(dash.array);
if (_strokeDashArrayData) {
free(_strokeDashArrayData);
}
dash.array = nil;
NSUInteger count = strokeDasharray.count;
dash.count = count;
if (count) {
dash.array = malloc(sizeof(CGFloat) * count);
for (NSUInteger i = 0; i < count; i++) {
dash.array[i] = (CGFloat)[self relativeOnOther:strokeDasharray[i]];
}
_strokeDashArrayData = malloc(sizeof(CGFloat) * count);
for (NSUInteger i = 0; i < count; i++) {
_strokeDashArrayData[i] = (CGFloat)[self relativeOnOther:strokeDasharray[i]];
}
_strokeDasharrayData = dash;
}
CGContextSetLineDash(context, self.strokeDashoffset, dash.array, dash.count);
CGContextSetLineDash(context, self.strokeDashoffset, _strokeDashArrayData, count);
}
if (!fillColor) {