From b5b1ececc0d76c41a95654bfb225b59e0fddcffd Mon Sep 17 00:00:00 2001 From: Mikael Sand Date: Sun, 12 Jan 2020 01:31:16 +0200 Subject: [PATCH] refactor(ios): only invalidate foreignObject on did mount if not ready --- ios/Elements/RNSVGForeignObject.m | 10 +++++++++- ios/Elements/RNSVGGroup.h | 1 + ios/Elements/RNSVGGroup.m | 11 ++++++++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ios/Elements/RNSVGForeignObject.m b/ios/Elements/RNSVGForeignObject.m index 2083b6c2..2371f957 100644 --- a/ios/Elements/RNSVGForeignObject.m +++ b/ios/Elements/RNSVGForeignObject.m @@ -40,12 +40,20 @@ - (void)uiManagerDidPerformMounting:(RCTUIManager *)manager { [manager addUIBlock:^(__unused RCTUIManager *uiManager, __unused NSDictionary *viewRegistry) { - if (!self->_ready && !self.dirty) { + if (!self->_ready) { [self invalidate]; } }]; } +- (void)renderChildTo:(CGContextRef)context rect:(CGRect)rect node:(UIView*)node +{ + node.hidden = false; + self->_ready = [node drawViewHierarchyInRect:rect afterScreenUpdates:true]; + [node.layer renderInContext:context]; + node.hidden = true; +} + - (void)renderLayerTo:(CGContextRef)context rect:(CGRect)rect { [self clip:context]; diff --git a/ios/Elements/RNSVGGroup.h b/ios/Elements/RNSVGGroup.h index 44020140..021d5c1e 100644 --- a/ios/Elements/RNSVGGroup.h +++ b/ios/Elements/RNSVGGroup.h @@ -20,6 +20,7 @@ - (void)renderPathTo:(CGContextRef)context rect:(CGRect)rect; - (void)renderGroupTo:(CGContextRef)context rect:(CGRect)rect; +- (void)renderChildTo:(CGContextRef)context rect:(CGRect)rect node:(UIView*)node; - (RNSVGGlyphContext *)getGlyphContext; - (void)pushGlyphContext; diff --git a/ios/Elements/RNSVGGroup.m b/ios/Elements/RNSVGGroup.m index 91a2a109..673c8393 100644 --- a/ios/Elements/RNSVGGroup.m +++ b/ios/Elements/RNSVGGroup.m @@ -72,9 +72,7 @@ CGContextClipToRect(context, rect); [svgView drawToContext:context withRect:rect]; } else { - node.hidden = false; - [node.layer renderInContext:context]; - node.hidden = true; + [self renderChildTo:context rect:rect node:node]; } return YES; @@ -107,6 +105,13 @@ [self popGlyphContext]; } +- (void)renderChildTo:(CGContextRef)context rect:(CGRect)rect node:(UIView*)node +{ + node.hidden = false; + [node.layer renderInContext:context]; + node.hidden = true; +} + - (void)setupGlyphContext:(CGContextRef)context { CGRect clipBounds = CGContextGetClipBoundingBox(context);