This commit is contained in:
Horcrux
2016-07-27 18:10:40 +08:00
parent fece0c0812
commit ab064d86e0
7 changed files with 81 additions and 19 deletions

View File

@@ -104,11 +104,21 @@ class SvgViewbox extends Component{
}
}
class NullComponent extends Component {
render() {
return null;
}
}
class SvgLayout extends Component{
static title = 'SVG with flex layout';
render() {
return <View style={styles.container}>
<Svg style={styles.svg}>
<G>
<NullComponent />
</G>
<NullComponent />
<Rect
width="80%"
height="80%"

View File

@@ -23,6 +23,10 @@ public class RNSVGDefsShadowNode extends RNSVGDefinitionShadowNode {
clip(canvas, paint);
for (int i = 0; i < getChildCount(); i++) {
if (!(getChildAt(i) instanceof RNSVGVirtualNode)) {
continue;
}
RNSVGVirtualNode child = (RNSVGVirtualNode) getChildAt(i);
child.saveDefinition();
}

View File

@@ -31,6 +31,10 @@ public class RNSVGGroupShadowNode extends RNSVGPathShadowNode {
int count = saveAndSetupCanvas(canvas);
clip(canvas, paint);
for (int i = 0; i < getChildCount(); i++) {
if (!(getChildAt(i) instanceof RNSVGVirtualNode)) {
continue;
}
RNSVGVirtualNode child = (RNSVGVirtualNode) getChildAt(i);
child.setupDimensions(canvas);
@@ -51,6 +55,10 @@ public class RNSVGGroupShadowNode extends RNSVGPathShadowNode {
Path path = new Path();
for (int i = 0; i < getChildCount(); i++) {
if (!(getChildAt(i) instanceof RNSVGVirtualNode)) {
continue;
}
RNSVGVirtualNode child = (RNSVGVirtualNode) getChildAt(i);
child.setupDimensions(canvas);
path.addPath(child.getPath(canvas, paint));
@@ -62,6 +70,10 @@ public class RNSVGGroupShadowNode extends RNSVGPathShadowNode {
public int hitTest(Point point, View view) {
int viewTag = -1;
for (int i = getChildCount() - 1; i >= 0; i--) {
if (!(getChildAt(i) instanceof RNSVGVirtualNode)) {
continue;
}
viewTag = ((RNSVGVirtualNode) getChildAt(i)).hitTest(point, ((ViewGroup) view).getChildAt(i));
if (viewTag != -1) {
break;
@@ -77,6 +89,10 @@ public class RNSVGGroupShadowNode extends RNSVGPathShadowNode {
}
for (int i = getChildCount() - 1; i >= 0; i--) {
if (!(getChildAt(i) instanceof RNSVGVirtualNode)) {
continue;
}
((RNSVGVirtualNode) getChildAt(i)).saveDefinition();
}
}
@@ -85,6 +101,10 @@ public class RNSVGGroupShadowNode extends RNSVGPathShadowNode {
public void mergeProperties(RNSVGVirtualNode target, ReadableArray mergeList) {
if (mergeList.size() != 0) {
for (int i = getChildCount() - 1; i >= 0; i--) {
if (!(getChildAt(i) instanceof RNSVGVirtualNode)) {
continue;
}
((RNSVGVirtualNode) getChildAt(i)).mergeProperties(target, mergeList);
}
}
@@ -93,6 +113,10 @@ public class RNSVGGroupShadowNode extends RNSVGPathShadowNode {
@Override
public void resetProperties() {
for (int i = getChildCount() - 1; i >= 0; i--) {
if (!(getChildAt(i) instanceof RNSVGVirtualNode)) {
continue;
}
((RNSVGVirtualNode) getChildAt(i)).resetProperties();
}
}

View File

@@ -62,6 +62,10 @@ public class RNSVGSvgViewShadowNode extends LayoutShadowNode {
*/
public synchronized void drawChildren(Canvas canvas, Paint paint) {
for (int i = 0; i < getChildCount(); i++) {
if (!(getChildAt(i) instanceof RNSVGVirtualNode)) {
continue;
}
RNSVGVirtualNode child = (RNSVGVirtualNode) getChildAt(i);
child.setupDimensions(canvas);
child.saveDefinition();
@@ -87,6 +91,10 @@ public class RNSVGSvgViewShadowNode extends LayoutShadowNode {
int count = getChildCount();
int viewTag = -1;
for (int i = count - 1; i >= 0; i--) {
if (!(getChildAt(i) instanceof RNSVGVirtualNode)) {
continue;
}
viewTag = ((RNSVGVirtualNode) getChildAt(i)).hitTest(point, view.getChildAt(i));
if (viewTag != -1) {
break;

View File

@@ -14,7 +14,9 @@
- (void)renderTo:(CGContextRef)context
{
for (RNSVGNode *node in self.subviews) {
[node saveDefinition];
if ([node isKindOfClass:[RNSVGNode class]]) {
[node saveDefinition];
}
}
}

View File

@@ -16,11 +16,13 @@
[self clip:context];
for (RNSVGNode *node in self.subviews) {
[node mergeProperties:self mergeList:self.propList inherited:YES];
[node renderTo:context];
if ([node isKindOfClass:[RNSVGNode class]]) {
[node mergeProperties:self mergeList:self.propList inherited:YES];
[node renderTo:context];
if (node.responsible && !svg.responsible) {
self.responsible = YES;
if (node.responsible && !svg.responsible) {
self.responsible = YES;
}
}
}
}
@@ -29,8 +31,10 @@
{
CGMutablePathRef path = CGPathCreateMutable();
for (RNSVGNode *node in self.subviews) {
CGAffineTransform transform = node.transform;
CGPathAddPath(path, &transform, [node getPath:context]);
if ([node isKindOfClass:[RNSVGNode class]]) {
CGAffineTransform transform = node.transform;
CGPathAddPath(path, &transform, [node getPath:context]);
}
}
return (CGPathRef)CFAutorelease(path);
}
@@ -39,9 +43,11 @@
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
for (RNSVGNode *node in [self.subviews reverseObjectEnumerator]) {
UIView *view = [node hitTest: point withEvent:event];
if (view) {
return view;
if ([node isKindOfClass:[RNSVGNode class]]) {
UIView *view = [node hitTest: point withEvent:event];
if (view) {
return view;
}
}
}
return nil;
@@ -55,21 +61,27 @@
}
for (RNSVGNode *node in self.subviews) {
[node saveDefinition];
if ([node isKindOfClass:[RNSVGNode class]]) {
[node saveDefinition];
}
}
}
- (void)mergeProperties:(__kindof RNSVGNode *)target mergeList:(NSArray<NSString *> *)mergeList
{
for (RNSVGNode *node in self.subviews) {
[node mergeProperties:target mergeList:mergeList];
if ([node isKindOfClass:[RNSVGNode class]]) {
[node mergeProperties:target mergeList:mergeList];
}
}
}
- (void)resetProperties
{
for (RNSVGNode *node in self.subviews) {
[node resetProperties];
if ([node isKindOfClass:[RNSVGNode class]]) {
[node resetProperties];
}
}
}

View File

@@ -49,11 +49,13 @@
CGContextRef context = UIGraphicsGetCurrentContext();
for (RNSVGNode *node in self.subviews) {
[node saveDefinition];
[node renderTo:context];
if ([node isKindOfClass:[RNSVGNode class]]) {
[node saveDefinition];
[node renderTo:context];
if (node.responsible && !self.responsible) {
self.responsible = YES;
if (node.responsible && !self.responsible) {
self.responsible = YES;
}
}
}
// CGImageRef image = CGBitmapContextCreateImage(context);