fix touch system on iOS

subViews in G will run hitTest now.
fix hitTest while using clipPath
This commit is contained in:
Horcrux
2016-05-18 18:30:51 +08:00
parent c9e4e3aead
commit 5c0aa77390
7 changed files with 53 additions and 15 deletions
+1 -1
View File
@@ -15,5 +15,5 @@
@interface RNSVGGroup : RNSVGNode <RNSVGContainer> @interface RNSVGGroup : RNSVGNode <RNSVGContainer>
@property (nonatomic, strong) NSString *asClipPath; // Current group is a <ClipPath /> element and asClipPath is its id. @property (nonatomic, strong) NSString *asClipPath; // Current group is a <ClipPath /> element and asClipPath is its id.
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event;
@end @end
+14
View File
@@ -33,4 +33,18 @@
return path; 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 @end
+4
View File
@@ -39,6 +39,8 @@
*/ */
- (void)clip:(CGContextRef)context; - (void)clip:(CGContextRef)context;
- (CGPathRef)getClipPath;
/** /**
* define <ClipPath></ClipPath> content as clipPath template. * define <ClipPath></ClipPath> content as clipPath template.
*/ */
@@ -49,4 +51,6 @@
*/ */
- (CGPathRef)getPath: (CGContextRef) context; - (CGPathRef)getPath: (CGContextRef) context;
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event;
@end @end
+24 -10
View File
@@ -35,10 +35,10 @@ static NSMutableDictionary *ClipPaths;
_opacity = opacity; _opacity = opacity;
} }
- (void)setTransform:(CGAffineTransform)transform - (void)setTrans:(CGAffineTransform)trans
{ {
[self invalidate]; [self invalidate];
super.transform = transform; super.transform = trans;
} }
- (void)invalidate - (void)invalidate
@@ -107,7 +107,7 @@ static NSMutableDictionary *ClipPaths;
return CGPathCreateMutable(); return CGPathCreateMutable();
} }
- (void)clip:(CGContextRef)context - (CGPathRef)getClipPath
{ {
CGPathRef clipPath = nil; CGPathRef clipPath = nil;
@@ -115,18 +115,26 @@ static NSMutableDictionary *ClipPaths;
clipPath = self.clipPath; clipPath = self.clipPath;
} else if (self.clipPathId) { } else if (self.clipPathId) {
clipPath = [[ClipPaths valueForKey:self.clipPathId] pointerValue]; clipPath = [[ClipPaths valueForKey:self.clipPathId] pointerValue];
} else {
return;
} }
CGContextAddPath(context, clipPath); return clipPath;
if (self.clipRule == kRNSVGCGFCRuleEvenodd) { }
CGContextEOClip(context);
} else { - (void)clip:(CGContextRef)context
CGContextClip(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 - (void)reactSetInheritedBackgroundColor:(UIColor *)inheritedBackgroundColor
{ {
self.backgroundColor = inheritedBackgroundColor; self.backgroundColor = inheritedBackgroundColor;
@@ -137,6 +145,12 @@ static NSMutableDictionary *ClipPaths;
// abstract // abstract
} }
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event;
{
// abstract
return nil;
}
- (void)dealloc - (void)dealloc
{ {
CGPathRelease(_clipPath); CGPathRelease(_clipPath);
+2
View File
@@ -25,4 +25,6 @@
@property (nonatomic, assign) CGFloat strokeDashoffset; @property (nonatomic, assign) CGFloat strokeDashoffset;
@property (nonatomic, assign) CGMutablePathRef nodeArea; @property (nonatomic, assign) CGMutablePathRef nodeArea;
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event;
@end @end
+7 -3
View File
@@ -92,11 +92,15 @@
} }
// hitTest delagate // hitTest delagate
- (UIView *)hitTest:(CGPoint)point - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
withEvent:(UIEvent *)event
{ {
CGPathRef clipPath = [self getClipPath];
if (self.nodeArea != NULL && CGPathContainsPoint(self.nodeArea, nil, point, NO)) { 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 { } else {
return nil; return nil;
} }
+1 -1
View File
@@ -30,7 +30,7 @@ RCT_EXPORT_MODULE()
} }
RCT_EXPORT_VIEW_PROPERTY(opacity, CGFloat) RCT_EXPORT_VIEW_PROPERTY(opacity, CGFloat)
RCT_EXPORT_VIEW_PROPERTY(transform, CGAffineTransform) RCT_EXPORT_VIEW_PROPERTY(trans, CGAffineTransform)
RCT_EXPORT_VIEW_PROPERTY(clipPathId, NSString) RCT_EXPORT_VIEW_PROPERTY(clipPathId, NSString)
@end @end