diff --git a/ios/Elements/RNSVGGroup.h b/ios/Elements/RNSVGGroup.h index 3a0828e2..59677451 100644 --- a/ios/Elements/RNSVGGroup.h +++ b/ios/Elements/RNSVGGroup.h @@ -15,5 +15,5 @@ @interface RNSVGGroup : RNSVGNode @property (nonatomic, strong) NSString *asClipPath; // Current group is a element and asClipPath is its id. - +- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event; @end diff --git a/ios/Elements/RNSVGGroup.m b/ios/Elements/RNSVGGroup.m index d132f24e..1fa5f4c9 100644 --- a/ios/Elements/RNSVGGroup.m +++ b/ios/Elements/RNSVGGroup.m @@ -33,4 +33,18 @@ return path; } +// hitTest delagate + +- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event +{ + for (RNSVGNode *node in [self.subviews reverseObjectEnumerator]) { + UIView *view = [node hitTest: point withEvent:event]; + + if (view != NULL) { + return view; + } + } + return nil; +} + @end diff --git a/ios/RNSVGNode.h b/ios/RNSVGNode.h index db6e0572..9c7d7861 100644 --- a/ios/RNSVGNode.h +++ b/ios/RNSVGNode.h @@ -39,6 +39,8 @@ */ - (void)clip:(CGContextRef)context; +- (CGPathRef)getClipPath; + /** * define content as clipPath template. */ @@ -49,4 +51,6 @@ */ - (CGPathRef)getPath: (CGContextRef) context; + +- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event; @end diff --git a/ios/RNSVGNode.m b/ios/RNSVGNode.m index 25aac4d7..1ab0992a 100644 --- a/ios/RNSVGNode.m +++ b/ios/RNSVGNode.m @@ -35,10 +35,10 @@ static NSMutableDictionary *ClipPaths; _opacity = opacity; } -- (void)setTransform:(CGAffineTransform)transform +- (void)setTrans:(CGAffineTransform)trans { [self invalidate]; - super.transform = transform; + super.transform = trans; } - (void)invalidate @@ -107,7 +107,7 @@ static NSMutableDictionary *ClipPaths; return CGPathCreateMutable(); } -- (void)clip:(CGContextRef)context +- (CGPathRef)getClipPath { CGPathRef clipPath = nil; @@ -115,18 +115,26 @@ static NSMutableDictionary *ClipPaths; clipPath = self.clipPath; } else if (self.clipPathId) { clipPath = [[ClipPaths valueForKey:self.clipPathId] pointerValue]; - } else { - return; } - CGContextAddPath(context, clipPath); - if (self.clipRule == kRNSVGCGFCRuleEvenodd) { - CGContextEOClip(context); - } else { - CGContextClip(context); + return clipPath; +} + +- (void)clip:(CGContextRef)context +{ + CGPathRef clipPath = [self getClipPath]; + + if (clipPath != NULL) { + CGContextAddPath(context, [self getClipPath]); + if (self.clipRule == kRNSVGCGFCRuleEvenodd) { + CGContextEOClip(context); + } else { + CGContextClip(context); + } } } + - (void)reactSetInheritedBackgroundColor:(UIColor *)inheritedBackgroundColor { self.backgroundColor = inheritedBackgroundColor; @@ -137,6 +145,12 @@ static NSMutableDictionary *ClipPaths; // abstract } +- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event; +{ + // abstract + return nil; +} + - (void)dealloc { CGPathRelease(_clipPath); diff --git a/ios/RNSVGRenderable.h b/ios/RNSVGRenderable.h index 993fcdab..3ebf9b85 100644 --- a/ios/RNSVGRenderable.h +++ b/ios/RNSVGRenderable.h @@ -25,4 +25,6 @@ @property (nonatomic, assign) CGFloat strokeDashoffset; @property (nonatomic, assign) CGMutablePathRef nodeArea; +- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event; + @end diff --git a/ios/RNSVGRenderable.m b/ios/RNSVGRenderable.m index e1919318..c740c6a0 100644 --- a/ios/RNSVGRenderable.m +++ b/ios/RNSVGRenderable.m @@ -92,11 +92,15 @@ } // hitTest delagate -- (UIView *)hitTest:(CGPoint)point - withEvent:(UIEvent *)event +- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { + CGPathRef clipPath = [self getClipPath]; if (self.nodeArea != NULL && CGPathContainsPoint(self.nodeArea, nil, point, NO)) { - return self; + if (clipPath == NULL) { + return self; + } else { + return CGPathContainsPoint(clipPath, nil, point, NO) ? self : nil; + } } else { return nil; } diff --git a/ios/ViewManagers/RNSVGNodeManager.m b/ios/ViewManagers/RNSVGNodeManager.m index 6f6d8861..90fd6234 100644 --- a/ios/ViewManagers/RNSVGNodeManager.m +++ b/ios/ViewManagers/RNSVGNodeManager.m @@ -30,7 +30,7 @@ RCT_EXPORT_MODULE() } RCT_EXPORT_VIEW_PROPERTY(opacity, CGFloat) -RCT_EXPORT_VIEW_PROPERTY(transform, CGAffineTransform) +RCT_EXPORT_VIEW_PROPERTY(trans, CGAffineTransform) RCT_EXPORT_VIEW_PROPERTY(clipPathId, NSString) @end