From 9384cc5e01b78a397796dbbd6e31387013ac2b48 Mon Sep 17 00:00:00 2001 From: Jakub Grzywacz Date: Wed, 2 Oct 2024 16:45:36 +0200 Subject: [PATCH] feat: use RCTConvert RNSVGBrush instead of brushFromColorStruct --- apple/Utils/RNSVGFabricConversions.h | 42 ++++++---------------------- 1 file changed, 8 insertions(+), 34 deletions(-) diff --git a/apple/Utils/RNSVGFabricConversions.h b/apple/Utils/RNSVGFabricConversions.h index f5b6906ae..fb01605c9 100644 --- a/apple/Utils/RNSVGFabricConversions.h +++ b/apple/Utils/RNSVGFabricConversions.h @@ -55,38 +55,6 @@ static id RNSVGConvertFollyDynamicToId(const folly::dynamic &dyn) } } -template -RNSVGBrush *brushFromColorStruct(const T &fillObject) -{ - int type = fillObject.type; - - switch (type) { - case -1: // empty struct - return nil; - case 0: // solid color - { - // These are probably expensive allocations since it's often the same value. - // We should memoize colors but look ups may be just as expensive. - RNSVGColor *color = RCTUIColorFromSharedColor(fillObject.payload) ?: [RNSVGColor clearColor]; - return [[RNSVGSolidColorBrush alloc] initWithColor:color]; - } - case 1: // brush - { - NSArray *arr = @[ @(type), RCTNSStringFromString(fillObject.brushRef) ]; - return [[RNSVGPainterBrush alloc] initWithArray:arr]; - } - case 2: // currentColor - return [[RNSVGBrush alloc] initWithArray:nil]; - case 3: // context-fill - return [[RNSVGContextBrush alloc] initFill]; - case 4: // context-stroke - return [[RNSVGContextBrush alloc] initStroke]; - default: - RCTLogError(@"Unknown brush type: %d", type); - return nil; - } -} - template void setCommonNodeProps(const T &nodeProps, RNSVGNode *node) { @@ -143,10 +111,16 @@ void setCommonRenderableProps(const T &renderableProps, RNSVGRenderable *rendera if (RCTUIColorFromSharedColor(renderableProps.color)) { [renderableNode setColor:RCTUIColorFromSharedColor(renderableProps.color)]; } - renderableNode.fill = brushFromColorStruct(renderableProps.fill); + id fill = RNSVGConvertFollyDynamicToId(renderableProps.fill); + if (fill != nil) { + renderableNode.fill = [RCTConvert RNSVGBrush:fill]; + } renderableNode.fillOpacity = renderableProps.fillOpacity; renderableNode.fillRule = renderableProps.fillRule == 0 ? kRNSVGCGFCRuleEvenodd : kRNSVGCGFCRuleNonzero; - renderableNode.stroke = brushFromColorStruct(renderableProps.stroke); + id stroke = RNSVGConvertFollyDynamicToId(renderableProps.stroke); + if (stroke != nil) { + renderableNode.stroke = [RCTConvert RNSVGBrush:stroke]; + } renderableNode.strokeOpacity = renderableProps.strokeOpacity; id strokeWidth = RNSVGConvertFollyDynamicToId(renderableProps.strokeWidth); if (strokeWidth != nil) {