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]]) {
+2 -2
View File
@@ -39,14 +39,14 @@ extern CGFloat const RNSVG_DEFAULT_FONT_SIZE;
- (RNSVGGroup *)getTextRoot;
- (RNSVGGroup *)getParentTextRoot;
- (void)renderTo:(CGContextRef)context;
- (void)renderTo:(CGContextRef)context rect:(CGRect)rect;
/**
* renderTo will take opacity into account and draw renderLayerTo off-screen if there is opacity
* specified, then composite that onto the context. renderLayerTo always draws at opacity=1.
* @abstract
*/
- (void)renderLayerTo:(CGContextRef)context;
- (void)renderLayerTo:(CGContextRef)context rect:(CGRect)rect;
/**
* get clipPath from cache
+4 -12
View File
@@ -159,7 +159,7 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12;
}
}
- (void)renderTo:(CGContextRef)context
- (void)renderTo:(CGContextRef)context rect:(CGRect)rect
{
// abstract
}
@@ -199,7 +199,7 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12;
return nil;
}
- (void)renderLayerTo:(CGContextRef)context
- (void)renderLayerTo:(CGContextRef)context rect:(CGRect)rect
{
// abstract
}
@@ -313,16 +313,8 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12;
- (void)traverseSubviews:(BOOL (^)(__kindof UIView *node))block
{
for (UIView *node in self.subviews) {
if ([node isKindOfClass:[RNSVGNode class]]) {
if (!block(node)) {
break;
}
} else if ([node isKindOfClass:[RNSVGSvgView class]]) {
if (!block(node)) {
break;
}
} else {
RCTLogWarn(@"Not a RNSVGNode: %@", node.class);
if (!block(node)) {
break;
}
}
}
+3 -3
View File
@@ -157,7 +157,7 @@
}
}
- (void)renderTo:(CGContextRef)context
- (void)renderTo:(CGContextRef)context rect:(CGRect)rect
{
// This needs to be painted on a layer before being composited.
CGContextSaveGState(context);
@@ -165,14 +165,14 @@
CGContextSetAlpha(context, self.opacity);
[self beginTransparencyLayer:context];
[self renderLayerTo:context];
[self renderLayerTo:context rect:rect];
[self endTransparencyLayer:context];
CGContextRestoreGState(context);
}
- (void)renderLayerTo:(CGContextRef)context
- (void)renderLayerTo:(CGContextRef)context rect:(CGRect)rect
{
if (!self.fill && !self.stroke) {
return;
+3 -3
View File
@@ -46,13 +46,13 @@ static double RNSVGTSpan_radToDeg = 180 / M_PI;
_content = content;
}
- (void)renderLayerTo:(CGContextRef)context
- (void)renderLayerTo:(CGContextRef)context rect:(CGRect)rect
{
if (self.content) {
[self renderPathTo:context];
[self renderPathTo:context rect:rect];
} else {
[self clip:context];
[self renderGroupTo:context];
[self renderGroupTo:context rect:rect];
}
}
+4 -4
View File
@@ -19,14 +19,14 @@
RNSVGGlyphContext *_glyphContext;
}
- (void)renderLayerTo:(CGContextRef)context
- (void)renderLayerTo:(CGContextRef)context rect:(CGRect)rect
{
[self clip:context];
CGContextSaveGState(context);
[self setupGlyphContext:context];
CGPathRef path = [self getGroupPath:context];
[self renderGroupTo:context];
[self renderGroupTo:context rect:rect];
[self releaseCachedPath];
CGContextRestoreGState(context);
@@ -69,10 +69,10 @@
return (CGPathRef)CFAutorelease(CGPathCreateCopyByTransformingPath(groupPath, &CGAffineTransformIdentity));
}
- (void)renderGroupTo:(CGContextRef)context
- (void)renderGroupTo:(CGContextRef)context rect:(CGRect)rect
{
[self pushGlyphContext];
[super renderGroupTo:context];
[super renderGroupTo:context rect:rect];
[self popGlyphContext];
}
+2 -2
View File
@@ -209,9 +209,9 @@ void RNSVGPerformanceBezier_addLine(CGPoint *last, const CGPoint *next, NSMutabl
*linesP = lines;
}
- (void)renderLayerTo:(CGContextRef)context
- (void)renderLayerTo:(CGContextRef)context rect:(CGRect)rect
{
[self renderGroupTo:context];
[self renderGroupTo:context rect:rect];
}
- (CGPathRef)getPath:(CGContextRef)context