From 08b1f5314737e0a18bcde8a89e3c4e89c26cd195 Mon Sep 17 00:00:00 2001 From: Jakub Grzywacz Date: Fri, 15 Nov 2024 13:13:36 +0100 Subject: [PATCH] fix: remove fill and stroke when its unset (#2536) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Summary Closes #2535 When `fill` or `stroke` is set to `'none'` we should remove the value instead of keeping the last valid value. ## Test Plan ```tsx import React, {useState} from 'react'; import {Text, TouchableOpacity} from 'react-native'; import {Path, Rect, Svg} from 'react-native-svg'; function Example() { const [color, setColor] = useState('#0000FF'); return ( <> setColor('none')}> Click to remove color ); } ``` ## Compatibility | OS | Implemented | | ------- | :---------: | | iOS | ✅ | | macOS | ✅ | --- apple/Utils/RCTConvert+RNSVG.mm | 3 +++ apple/Utils/RNSVGFabricConversions.h | 8 ++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/apple/Utils/RCTConvert+RNSVG.mm b/apple/Utils/RCTConvert+RNSVG.mm index 63da345c..b65cae7d 100644 --- a/apple/Utils/RCTConvert+RNSVG.mm +++ b/apple/Utils/RCTConvert+RNSVG.mm @@ -100,6 +100,9 @@ RCT_ENUM_CONVERTER( + (RNSVGBrush *)RNSVGBrush:(id)json { + if (json == nil) { + return nil; + } if ([json isKindOfClass:[NSNumber class]]) { return [[RNSVGSolidColorBrush alloc] initWithNumber:json]; } diff --git a/apple/Utils/RNSVGFabricConversions.h b/apple/Utils/RNSVGFabricConversions.h index fb01605c..cf625ac4 100644 --- a/apple/Utils/RNSVGFabricConversions.h +++ b/apple/Utils/RNSVGFabricConversions.h @@ -112,15 +112,11 @@ void setCommonRenderableProps(const T &renderableProps, RNSVGRenderable *rendera [renderableNode setColor:RCTUIColorFromSharedColor(renderableProps.color)]; } id fill = RNSVGConvertFollyDynamicToId(renderableProps.fill); - if (fill != nil) { - renderableNode.fill = [RCTConvert RNSVGBrush:fill]; - } + renderableNode.fill = [RCTConvert RNSVGBrush:fill]; renderableNode.fillOpacity = renderableProps.fillOpacity; renderableNode.fillRule = renderableProps.fillRule == 0 ? kRNSVGCGFCRuleEvenodd : kRNSVGCGFCRuleNonzero; id stroke = RNSVGConvertFollyDynamicToId(renderableProps.stroke); - if (stroke != nil) { - renderableNode.stroke = [RCTConvert RNSVGBrush:stroke]; - } + renderableNode.stroke = [RCTConvert RNSVGBrush:stroke]; renderableNode.strokeOpacity = renderableProps.strokeOpacity; id strokeWidth = RNSVGConvertFollyDynamicToId(renderableProps.strokeWidth); if (strokeWidth != nil) {