@@ -34,6 +34,7 @@ - (instancetype)initWithFrame:(CGRect)frame
3434 if (self = [super initWithFrame: frame]) {
3535 static const auto defaultProps = std::make_shared<const RNSVGForeignObjectProps>();
3636 _props = defaultProps;
37+ _managedNodes = [NSHashTable weakObjectsHashTable ];
3738 }
3839 return self;
3940}
@@ -77,6 +78,12 @@ - (void)prepareForRecycle
7778 _y = nil ;
7879 _foreignObjectheight = nil ;
7980 _foreignObjectwidth = nil ;
81+
82+ for (RNSVGView *node in self.managedNodes ) {
83+ node.hidden = NO ;
84+ }
85+
86+ [self .managedNodes removeAllObjects ];
8087}
8188#endif // RCT_NEW_ARCH_ENABLED
8289- (RNSVGPlatformView *)hitTest : (CGPoint)point withEvent : (UIEvent *)event
@@ -139,9 +146,32 @@ - (void)renderGroupTo:(CGContextRef)context rect:(CGRect)rect
139146 CGContextClipToRect (context, svgViewRect);
140147 [svgView drawToContext: context withRect: svgViewRect];
141148 } else {
142- node.hidden = false ;
149+ CATransform3D transform = node.layer .transform ;
150+
151+ #ifdef RCT_NEW_ARCH_ENABLED
152+ [self .managedNodes addObject: node];
153+ #endif
154+
155+ CGContextSaveGState (context);
156+ CGRect bounds = node.layer .bounds ;
157+ CGPoint position = node.layer .position ;
158+
159+ CGContextTranslateCTM (context, position.x , position.y );
160+
161+ if (!CATransform3DIsIdentity (transform)) {
162+ CGAffineTransform affine = CATransform3DGetAffineTransform (transform);
163+ CGContextConcatCTM (context, affine);
164+ }
165+
166+ // This moves the origin from that center point to the object's top-left corner,
167+ // which is where drawing operations will begin.
168+ CGContextTranslateCTM (context, -bounds.size .width / 2 , -bounds.size .height / 2 );
169+
170+ node.hidden = NO ;
143171 [node.layer renderInContext: context];
144- node.hidden = true ;
172+ node.hidden = YES ;
173+
174+ CGContextRestoreGState (context);
145175 }
146176
147177 return YES ;
@@ -173,6 +203,20 @@ - (void)renderGroupTo:(CGContextRef)context rect:(CGRect)rect
173203 [self popGlyphContext ];
174204}
175205
206+ #ifdef RCT_NEW_ARCH_ENABLED
207+ - (void )layoutSubviews
208+ {
209+ [super layoutSubviews ];
210+
211+ // We know layout is done, but the async text rendering is not.
212+ // We schedule the SVG redraw for the next runloop cycle.
213+ // This gives the text layout system time to finish its work.
214+ dispatch_async (dispatch_get_main_queue (), ^{
215+ [self invalidate ];
216+ });
217+ }
218+ #endif
219+
176220- (void )drawRect : (CGRect)rect
177221{
178222 [self invalidate ];
0 commit comments