Skip to content

Commit

Permalink
feat: use RCTConvert RNSVGBrush instead of brushFromColorStruct
Browse files Browse the repository at this point in the history
  • Loading branch information
jakex7 committed Oct 2, 2024
1 parent 992a06e commit 9384cc5
Showing 1 changed file with 8 additions and 34 deletions.
42 changes: 8 additions & 34 deletions apple/Utils/RNSVGFabricConversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,38 +55,6 @@ static id RNSVGConvertFollyDynamicToId(const folly::dynamic &dyn)
}
}

template <typename T>
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 <typename T>
void setCommonNodeProps(const T &nodeProps, RNSVGNode *node)
{
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 9384cc5

Please sign in to comment.