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>
@property (nonatomic, strong) NSString *asClipPath; // Current group is a <ClipPath /> element and asClipPath is its id.
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event;
@end
+14
View File
@@ -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
+4
View File
@@ -39,6 +39,8 @@
*/
- (void)clip:(CGContextRef)context;
- (CGPathRef)getClipPath;
/**
* define <ClipPath></ClipPath> content as clipPath template.
*/
@@ -49,4 +51,6 @@
*/
- (CGPathRef)getPath: (CGContextRef) context;
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event;
@end
+24 -10
View File
@@ -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);
+2
View File
@@ -25,4 +25,6 @@
@property (nonatomic, assign) CGFloat strokeDashoffset;
@property (nonatomic, assign) CGMutablePathRef nodeArea;
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event;
@end
+7 -3
View File
@@ -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;
}
+1 -1
View File
@@ -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