Allow nesting React-Native View components inside svg

This commit is contained in:
Mikael Sand
2018-02-21 00:48:03 +02:00
parent ee1d1f78cc
commit b5eeb1ee72
11 changed files with 35 additions and 43 deletions
+2 -2
View File
@@ -18,8 +18,8 @@
@property (nonatomic, strong) NSDictionary *font;
- (void)renderPathTo:(CGContextRef)context;
- (void)renderGroupTo:(CGContextRef)context;
- (void)renderPathTo:(CGContextRef)context rect:(CGRect)rect;
- (void)renderGroupTo:(CGContextRef)context rect:(CGRect)rect;
- (RNSVGGlyphContext *)getGlyphContext;
- (void)pushGlyphContext;
+7 -7
View File
@@ -23,14 +23,14 @@
_font = font;
}
- (void)renderLayerTo:(CGContextRef)context
- (void)renderLayerTo:(CGContextRef)context rect:(CGRect)rect
{
[self clip:context];
[self setupGlyphContext:context];
[self renderGroupTo:context];
[self renderGroupTo:context rect:rect];
}
- (void)renderGroupTo:(CGContextRef)context
- (void)renderGroupTo:(CGContextRef)context rect:(CGRect)rect
{
[self pushGlyphContext];
RNSVGSvgView* svg = [self getSvgView];
@@ -45,7 +45,7 @@
[(RNSVGRenderable*)node mergeProperties:self];
}
[svgNode renderTo:context];
[svgNode renderTo:context rect:rect];
if ([node isKindOfClass:[RNSVGRenderable class]]) {
[(RNSVGRenderable*)node resetProperties];
@@ -56,7 +56,7 @@
CGContextClipToRect(context, rect);
[svgView drawToContext:context withRect:(CGRect)rect];
} else {
RCTLogWarn(@"Not a RNSVGNode: %@", node.class);
[node drawRect:rect];
}
return YES;
@@ -90,9 +90,9 @@
[[[self getTextRoot] getGlyphContext] popContext];
}
- (void)renderPathTo:(CGContextRef)context
- (void)renderPathTo:(CGContextRef)context rect:(CGRect)rect
{
[super renderLayerTo:context];
[super renderLayerTo:context rect:rect];
}
- (CGPathRef)getPath:(CGContextRef)context
+3 -3
View File
@@ -135,7 +135,9 @@
for (UIView *node in self.subviews) {
if ([node isKindOfClass:[RNSVGNode class]]) {
RNSVGNode *svg = (RNSVGNode *)node;
[svg renderTo:context];
[svg renderTo:context rect:rect];
} else {
[node drawRect:rect];
}
}
}
@@ -156,8 +158,6 @@
}
[svg parseReference];
} else {
RCTLogWarn(@"Not a RNSVGNode: %@", node.class);
}
}
+3 -3
View File
@@ -72,15 +72,15 @@
_meetOrSlice = meetOrSlice;
}
- (void)renderTo:(CGContextRef)context
- (void)renderTo:(CGContextRef)context rect:(CGRect)rect
{
// Do not render Symbol
}
- (void)renderSymbolTo:(CGContextRef)context width:(CGFloat)width height:(CGFloat)height
{
CGRect eRect = CGRectMake(0, 0, width, height);
if (self.align) {
CGRect eRect = CGRectMake(0, 0, width, height);
CGAffineTransform viewBoxTransform = [RNSVGViewBox getTransform:CGRectMake(self.minX, self.minY, self.vbWidth, self.vbHeight)
eRect:eRect
@@ -89,7 +89,7 @@
CGContextConcatCTM(context, viewBoxTransform);
}
[self renderGroupTo:context];
[self renderGroupTo:context rect:eRect];
}
@end
+2 -2
View File
@@ -22,7 +22,7 @@
}
- (void)renderLayerTo:(CGContextRef)context
- (void)renderLayerTo:(CGContextRef)context rect:(CGRect)rect
{
RNSVGNode* template = [[self getSvgView] getDefinedTemplate:self.href];
if (template) {
@@ -37,7 +37,7 @@
RNSVGSymbol *symbol = (RNSVGSymbol*)template;
[symbol renderSymbolTo:context width:[self relativeOnWidth:self.width] height:[self relativeOnWidth:self.height]];
} else {
[template renderTo:context];
[template renderTo:context rect:rect];
}
if ([template isKindOfClass:[RNSVGRenderable class]]) {