fix touch events within the elements which are nested in G

This commit is contained in:
Horcrux
2016-08-06 21:37:58 +08:00
parent 76a51f1f47
commit 7f4eb47f81
17 changed files with 123 additions and 121 deletions
-3
View File
@@ -14,7 +14,4 @@
#import "RNSVGRenderable.h"
@interface RNSVGGroup : RNSVGRenderable <RNSVGContainer>
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event;
@end
+21 -9
View File
@@ -14,14 +14,14 @@
{
RNSVGSvgView* svg = [self getSvgView];
[self clip:context];
for (RNSVGNode *node in self.subviews) {
if ([node isKindOfClass:[RNSVGNode class]]) {
[node mergeProperties:self mergeList:self.propList inherited:YES];
[node renderTo:context];
if (node.responsible && !svg.responsible) {
self.responsible = YES;
svg.responsible = YES;
}
}
}
@@ -32,21 +32,33 @@
CGMutablePathRef path = CGPathCreateMutable();
for (RNSVGNode *node in self.subviews) {
if ([node isKindOfClass:[RNSVGNode class]]) {
CGAffineTransform transform = node.transform;
CGAffineTransform transform = node.matrix;
CGPathAddPath(path, &transform, [node getPath:context]);
}
}
return (CGPathRef)CFAutorelease(path);
}
// hitTest delagate
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event withTransform:(CGAffineTransform)transform
{
CGAffineTransform matrix = CGAffineTransformConcat(self.matrix, transform);
for (RNSVGNode *node in [self.subviews reverseObjectEnumerator]) {
if ([node isKindOfClass:[RNSVGNode class]]) {
UIView *view = [node hitTest: point withEvent:event];
if (event) {
node.active = NO;
}
if (node.active) {
return node;
}
UIView *view = [node hitTest: point withEvent:event withTransform:matrix];
if (view) {
if (node.responsible || node != view) {
node.active = YES;
if (node.responsible || (node != view)) {
return view;
} else {
return self;
@@ -63,7 +75,7 @@
RNSVGSvgView* svg = [self getSvgView];
[svg defineTemplate:self templateRef:self.name];
}
for (RNSVGNode *node in self.subviews) {
if ([node isKindOfClass:[RNSVGNode class]]) {
[node saveDefinition];
+2 -7
View File
@@ -71,10 +71,7 @@
{
CGRect rect = [self getRect:context];
// add hit area
self.hitArea = CGPathCreateMutable();
CGPathRef path = CGPathCreateWithRect(rect, nil);
CGPathAddPath(self.hitArea, nil, path);
CGPathRelease(path);
self.hitArea = CGPathCreateWithRect(rect, nil);
[self clip:context];
CGContextSaveGState(context);
@@ -97,9 +94,7 @@
- (CGPathRef)getPath:(CGContextRef)context
{
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddRect(path, nil, [self getRect:context]);
return (CGPathRef)CFAutorelease(path);
return CGPathCreateWithRect([self getRect:context], nil);
}
@end
+16 -10
View File
@@ -15,6 +15,7 @@
if (d == _d) {
return;
}
[self invalidate];
CGPathRelease(_d);
_d = CGPathRetain(d);
@@ -27,20 +28,25 @@
- (void)renderLayerTo:(CGContextRef)context
{
if ((!self.fill && !self.stroke) || !self.d) {
CGPathRef path = [self getPath:context];
if ((!self.fill && !self.stroke) || !path) {
return;
}
// Add path to hitArea
self.hitArea = CGPathCreateMutableCopy(_d);
CGMutablePathRef hitArea = CGPathCreateMutableCopy(path);
if (self.stroke) {
// Add stroke to hitArea
CGPathRef strokePath = CGPathCreateCopyByStrokingPath(_d, nil, self.strokeWidth, self.strokeLinecap, self.strokeLinejoin, self.strokeMiterlimit);
CGPathAddPath(self.hitArea, nil, strokePath);
CGPathRef strokePath = CGPathCreateCopyByStrokingPath(hitArea, nil, self.strokeWidth, self.strokeLinecap, self.strokeLinejoin, self.strokeMiterlimit);
CGPathAddPath(hitArea, nil, strokePath);
CGPathRelease(strokePath);
}
CGAffineTransform transform = self.matrix;
self.hitArea = CGPathCreateCopyByTransformingPath(hitArea, &transform);
CGPathRelease(hitArea);
if (self.opacity == 0) {
return;
}
@@ -56,7 +62,7 @@
[self clip:context];
CGContextSaveGState(context);
CGContextAddPath(context, self.d);
CGContextAddPath(context, path);
CGContextClip(context);
RNSVGBrushConverter *brushConverter = [[self getSvgView] getDefinedBrushConverter:[self.fill brushRef]];
[self.fill paint:context opacity:self.fillOpacity brushConverter:brushConverter];
@@ -78,7 +84,7 @@
}
if (!fillColor) {
CGContextAddPath(context, self.d);
CGContextAddPath(context, path);
CGContextReplacePathWithStrokedPath(context);
CGContextClip(context);
}
@@ -92,11 +98,11 @@
} else {
// draw fill
[self clip:context];
CGContextAddPath(context, self.d);
CGContextAddPath(context, path);
CGContextDrawPath(context, mode);
// draw stroke
CGContextAddPath(context, self.d);
CGContextAddPath(context, path);
CGContextReplacePathWithStrokedPath(context);
CGContextClip(context);
RNSVGBrushConverter *brushConverter = [[self getSvgView] getDefinedBrushConverter:[self.stroke brushRef]];
@@ -106,7 +112,7 @@
}
[self clip:context];
CGContextAddPath(context, self.d);
CGContextAddPath(context, path);
CGContextDrawPath(context, mode);
}