diff --git a/apple/Elements/RNSVGSvgView.mm b/apple/Elements/RNSVGSvgView.mm index e6261f1fd..736121d70 100644 --- a/apple/Elements/RNSVGSvgView.mm +++ b/apple/Elements/RNSVGSvgView.mm @@ -32,6 +32,7 @@ @implementation RNSVGSvgView { NSMutableDictionary *_filters; CGAffineTransform _invViewBoxTransform; bool rendered; + CGRect _lastBounds; } #ifdef RCT_NEW_ARCH_ENABLED @@ -283,6 +284,31 @@ - (void)setMeetOrSlice:(RNSVGVBMOS)meetOrSlice _meetOrSlice = meetOrSlice; } +- (void)layoutSubviews +{ + [super layoutSubviews]; + + if (!CGRectEqualToRect(self.bounds, _lastBounds)) { + _lastBounds = self.bounds; + [self invalidateAllSVGNodes:self.subviews]; + [self invalidate]; + [self clearChildCache]; + } +} + +- (void)invalidateAllSVGNodes:(NSArray *)subviews +{ + for (__kindof RNSVGNode *node in subviews) { + if ([node isKindOfClass:[RNSVGNode class]]) { + [node invalidate]; + + if ([node respondsToSelector:@selector(subviews)] && [node subviews].count > 0) { + [self invalidateAllSVGNodes:[node subviews]]; + } + } + } +} + - (void)drawToContext:(CGContextRef)context withRect:(CGRect)rect { rendered = true; diff --git a/apps/common/test/Test2671.tsx b/apps/common/test/Test2671.tsx new file mode 100644 index 000000000..1682706c2 --- /dev/null +++ b/apps/common/test/Test2671.tsx @@ -0,0 +1,108 @@ +import {useState} from 'react'; +import {View, Button, Text, Dimensions, StyleSheet} from 'react-native'; +import Svg, {Line, Rect} from 'react-native-svg'; + +const initialWidth = 150; + +const deviceHeight = Dimensions.get('window').height; + +export default function Test2671() { + const [width, setWidth] = useState(initialWidth); + + const lineContainerStyles = { + width, + paddingTop: 40, + }; + return ( + +