mirror of
https://github.com/zoriya/react-native-svg.git
synced 2025-12-20 05:55:10 +00:00
fix #84
This commit is contained in:
@@ -104,11 +104,21 @@ class SvgViewbox extends Component{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class NullComponent extends Component {
|
||||||
|
render() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class SvgLayout extends Component{
|
class SvgLayout extends Component{
|
||||||
static title = 'SVG with flex layout';
|
static title = 'SVG with flex layout';
|
||||||
render() {
|
render() {
|
||||||
return <View style={styles.container}>
|
return <View style={styles.container}>
|
||||||
<Svg style={styles.svg}>
|
<Svg style={styles.svg}>
|
||||||
|
<G>
|
||||||
|
<NullComponent />
|
||||||
|
</G>
|
||||||
|
<NullComponent />
|
||||||
<Rect
|
<Rect
|
||||||
width="80%"
|
width="80%"
|
||||||
height="80%"
|
height="80%"
|
||||||
|
|||||||
@@ -23,6 +23,10 @@ public class RNSVGDefsShadowNode extends RNSVGDefinitionShadowNode {
|
|||||||
clip(canvas, paint);
|
clip(canvas, paint);
|
||||||
|
|
||||||
for (int i = 0; i < getChildCount(); i++) {
|
for (int i = 0; i < getChildCount(); i++) {
|
||||||
|
if (!(getChildAt(i) instanceof RNSVGVirtualNode)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
RNSVGVirtualNode child = (RNSVGVirtualNode) getChildAt(i);
|
RNSVGVirtualNode child = (RNSVGVirtualNode) getChildAt(i);
|
||||||
child.saveDefinition();
|
child.saveDefinition();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,10 @@ public class RNSVGGroupShadowNode extends RNSVGPathShadowNode {
|
|||||||
int count = saveAndSetupCanvas(canvas);
|
int count = saveAndSetupCanvas(canvas);
|
||||||
clip(canvas, paint);
|
clip(canvas, paint);
|
||||||
for (int i = 0; i < getChildCount(); i++) {
|
for (int i = 0; i < getChildCount(); i++) {
|
||||||
|
if (!(getChildAt(i) instanceof RNSVGVirtualNode)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
RNSVGVirtualNode child = (RNSVGVirtualNode) getChildAt(i);
|
RNSVGVirtualNode child = (RNSVGVirtualNode) getChildAt(i);
|
||||||
child.setupDimensions(canvas);
|
child.setupDimensions(canvas);
|
||||||
|
|
||||||
@@ -51,6 +55,10 @@ public class RNSVGGroupShadowNode extends RNSVGPathShadowNode {
|
|||||||
Path path = new Path();
|
Path path = new Path();
|
||||||
|
|
||||||
for (int i = 0; i < getChildCount(); i++) {
|
for (int i = 0; i < getChildCount(); i++) {
|
||||||
|
if (!(getChildAt(i) instanceof RNSVGVirtualNode)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
RNSVGVirtualNode child = (RNSVGVirtualNode) getChildAt(i);
|
RNSVGVirtualNode child = (RNSVGVirtualNode) getChildAt(i);
|
||||||
child.setupDimensions(canvas);
|
child.setupDimensions(canvas);
|
||||||
path.addPath(child.getPath(canvas, paint));
|
path.addPath(child.getPath(canvas, paint));
|
||||||
@@ -62,6 +70,10 @@ public class RNSVGGroupShadowNode extends RNSVGPathShadowNode {
|
|||||||
public int hitTest(Point point, View view) {
|
public int hitTest(Point point, View view) {
|
||||||
int viewTag = -1;
|
int viewTag = -1;
|
||||||
for (int i = getChildCount() - 1; i >= 0; i--) {
|
for (int i = getChildCount() - 1; i >= 0; i--) {
|
||||||
|
if (!(getChildAt(i) instanceof RNSVGVirtualNode)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
viewTag = ((RNSVGVirtualNode) getChildAt(i)).hitTest(point, ((ViewGroup) view).getChildAt(i));
|
viewTag = ((RNSVGVirtualNode) getChildAt(i)).hitTest(point, ((ViewGroup) view).getChildAt(i));
|
||||||
if (viewTag != -1) {
|
if (viewTag != -1) {
|
||||||
break;
|
break;
|
||||||
@@ -77,6 +89,10 @@ public class RNSVGGroupShadowNode extends RNSVGPathShadowNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int i = getChildCount() - 1; i >= 0; i--) {
|
for (int i = getChildCount() - 1; i >= 0; i--) {
|
||||||
|
if (!(getChildAt(i) instanceof RNSVGVirtualNode)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
((RNSVGVirtualNode) getChildAt(i)).saveDefinition();
|
((RNSVGVirtualNode) getChildAt(i)).saveDefinition();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,6 +101,10 @@ public class RNSVGGroupShadowNode extends RNSVGPathShadowNode {
|
|||||||
public void mergeProperties(RNSVGVirtualNode target, ReadableArray mergeList) {
|
public void mergeProperties(RNSVGVirtualNode target, ReadableArray mergeList) {
|
||||||
if (mergeList.size() != 0) {
|
if (mergeList.size() != 0) {
|
||||||
for (int i = getChildCount() - 1; i >= 0; i--) {
|
for (int i = getChildCount() - 1; i >= 0; i--) {
|
||||||
|
if (!(getChildAt(i) instanceof RNSVGVirtualNode)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
((RNSVGVirtualNode) getChildAt(i)).mergeProperties(target, mergeList);
|
((RNSVGVirtualNode) getChildAt(i)).mergeProperties(target, mergeList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,6 +113,10 @@ public class RNSVGGroupShadowNode extends RNSVGPathShadowNode {
|
|||||||
@Override
|
@Override
|
||||||
public void resetProperties() {
|
public void resetProperties() {
|
||||||
for (int i = getChildCount() - 1; i >= 0; i--) {
|
for (int i = getChildCount() - 1; i >= 0; i--) {
|
||||||
|
if (!(getChildAt(i) instanceof RNSVGVirtualNode)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
((RNSVGVirtualNode) getChildAt(i)).resetProperties();
|
((RNSVGVirtualNode) getChildAt(i)).resetProperties();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,6 +62,10 @@ public class RNSVGSvgViewShadowNode extends LayoutShadowNode {
|
|||||||
*/
|
*/
|
||||||
public synchronized void drawChildren(Canvas canvas, Paint paint) {
|
public synchronized void drawChildren(Canvas canvas, Paint paint) {
|
||||||
for (int i = 0; i < getChildCount(); i++) {
|
for (int i = 0; i < getChildCount(); i++) {
|
||||||
|
if (!(getChildAt(i) instanceof RNSVGVirtualNode)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
RNSVGVirtualNode child = (RNSVGVirtualNode) getChildAt(i);
|
RNSVGVirtualNode child = (RNSVGVirtualNode) getChildAt(i);
|
||||||
child.setupDimensions(canvas);
|
child.setupDimensions(canvas);
|
||||||
child.saveDefinition();
|
child.saveDefinition();
|
||||||
@@ -87,6 +91,10 @@ public class RNSVGSvgViewShadowNode extends LayoutShadowNode {
|
|||||||
int count = getChildCount();
|
int count = getChildCount();
|
||||||
int viewTag = -1;
|
int viewTag = -1;
|
||||||
for (int i = count - 1; i >= 0; i--) {
|
for (int i = count - 1; i >= 0; i--) {
|
||||||
|
if (!(getChildAt(i) instanceof RNSVGVirtualNode)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
viewTag = ((RNSVGVirtualNode) getChildAt(i)).hitTest(point, view.getChildAt(i));
|
viewTag = ((RNSVGVirtualNode) getChildAt(i)).hitTest(point, view.getChildAt(i));
|
||||||
if (viewTag != -1) {
|
if (viewTag != -1) {
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -14,7 +14,9 @@
|
|||||||
- (void)renderTo:(CGContextRef)context
|
- (void)renderTo:(CGContextRef)context
|
||||||
{
|
{
|
||||||
for (RNSVGNode *node in self.subviews) {
|
for (RNSVGNode *node in self.subviews) {
|
||||||
[node saveDefinition];
|
if ([node isKindOfClass:[RNSVGNode class]]) {
|
||||||
|
[node saveDefinition];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,11 +16,13 @@
|
|||||||
[self clip:context];
|
[self clip:context];
|
||||||
|
|
||||||
for (RNSVGNode *node in self.subviews) {
|
for (RNSVGNode *node in self.subviews) {
|
||||||
[node mergeProperties:self mergeList:self.propList inherited:YES];
|
if ([node isKindOfClass:[RNSVGNode class]]) {
|
||||||
[node renderTo:context];
|
[node mergeProperties:self mergeList:self.propList inherited:YES];
|
||||||
|
[node renderTo:context];
|
||||||
|
|
||||||
if (node.responsible && !svg.responsible) {
|
if (node.responsible && !svg.responsible) {
|
||||||
self.responsible = YES;
|
self.responsible = YES;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -29,8 +31,10 @@
|
|||||||
{
|
{
|
||||||
CGMutablePathRef path = CGPathCreateMutable();
|
CGMutablePathRef path = CGPathCreateMutable();
|
||||||
for (RNSVGNode *node in self.subviews) {
|
for (RNSVGNode *node in self.subviews) {
|
||||||
CGAffineTransform transform = node.transform;
|
if ([node isKindOfClass:[RNSVGNode class]]) {
|
||||||
CGPathAddPath(path, &transform, [node getPath:context]);
|
CGAffineTransform transform = node.transform;
|
||||||
|
CGPathAddPath(path, &transform, [node getPath:context]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return (CGPathRef)CFAutorelease(path);
|
return (CGPathRef)CFAutorelease(path);
|
||||||
}
|
}
|
||||||
@@ -39,9 +43,11 @@
|
|||||||
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
|
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
|
||||||
{
|
{
|
||||||
for (RNSVGNode *node in [self.subviews reverseObjectEnumerator]) {
|
for (RNSVGNode *node in [self.subviews reverseObjectEnumerator]) {
|
||||||
UIView *view = [node hitTest: point withEvent:event];
|
if ([node isKindOfClass:[RNSVGNode class]]) {
|
||||||
if (view) {
|
UIView *view = [node hitTest: point withEvent:event];
|
||||||
return view;
|
if (view) {
|
||||||
|
return view;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil;
|
return nil;
|
||||||
@@ -55,21 +61,27 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (RNSVGNode *node in self.subviews) {
|
for (RNSVGNode *node in self.subviews) {
|
||||||
[node saveDefinition];
|
if ([node isKindOfClass:[RNSVGNode class]]) {
|
||||||
|
[node saveDefinition];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)mergeProperties:(__kindof RNSVGNode *)target mergeList:(NSArray<NSString *> *)mergeList
|
- (void)mergeProperties:(__kindof RNSVGNode *)target mergeList:(NSArray<NSString *> *)mergeList
|
||||||
{
|
{
|
||||||
for (RNSVGNode *node in self.subviews) {
|
for (RNSVGNode *node in self.subviews) {
|
||||||
[node mergeProperties:target mergeList:mergeList];
|
if ([node isKindOfClass:[RNSVGNode class]]) {
|
||||||
|
[node mergeProperties:target mergeList:mergeList];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)resetProperties
|
- (void)resetProperties
|
||||||
{
|
{
|
||||||
for (RNSVGNode *node in self.subviews) {
|
for (RNSVGNode *node in self.subviews) {
|
||||||
[node resetProperties];
|
if ([node isKindOfClass:[RNSVGNode class]]) {
|
||||||
|
[node resetProperties];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,11 +49,13 @@
|
|||||||
CGContextRef context = UIGraphicsGetCurrentContext();
|
CGContextRef context = UIGraphicsGetCurrentContext();
|
||||||
|
|
||||||
for (RNSVGNode *node in self.subviews) {
|
for (RNSVGNode *node in self.subviews) {
|
||||||
[node saveDefinition];
|
if ([node isKindOfClass:[RNSVGNode class]]) {
|
||||||
[node renderTo:context];
|
[node saveDefinition];
|
||||||
|
[node renderTo:context];
|
||||||
|
|
||||||
if (node.responsible && !self.responsible) {
|
if (node.responsible && !self.responsible) {
|
||||||
self.responsible = YES;
|
self.responsible = YES;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// CGImageRef image = CGBitmapContextCreateImage(context);
|
// CGImageRef image = CGBitmapContextCreateImage(context);
|
||||||
|
|||||||
Reference in New Issue
Block a user