mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-01 06:07:41 +00:00
Optimize hit testing.
This commit is contained in:
@@ -109,25 +109,21 @@
|
||||
return (CGPathRef)CFAutorelease(path);
|
||||
}
|
||||
|
||||
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event withTransform:(CGAffineTransform)transform
|
||||
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
|
||||
{
|
||||
UIView *hitSelf = [super hitTest:point withEvent:event withTransform:transform];
|
||||
CGPoint transformed = CGPointApplyAffineTransform(point, CGAffineTransformInvert(self.matrix));
|
||||
|
||||
UIView *hitSelf = [super hitTest:transformed withEvent:event];
|
||||
if (hitSelf) {
|
||||
return hitSelf;
|
||||
}
|
||||
|
||||
CGAffineTransform matrix = CGAffineTransformConcat(self.matrix, transform);
|
||||
|
||||
CGPathRef clip = [self getClipPath];
|
||||
if (clip) {
|
||||
CGPathRef transformedClipPath = CGPathCreateCopyByTransformingPath(clip, &matrix);
|
||||
BOOL insideClipPath = CGPathContainsPoint(clip, nil, point, self.clipRule == kRNSVGCGFCRuleEvenodd);
|
||||
CGPathRelease(transformedClipPath);
|
||||
|
||||
BOOL insideClipPath = CGPathContainsPoint(clip, nil, transformed, self.clipRule == kRNSVGCGFCRuleEvenodd);
|
||||
if (!insideClipPath) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (RNSVGNode *node in [self.subviews reverseObjectEnumerator]) {
|
||||
@@ -141,13 +137,14 @@
|
||||
return node;
|
||||
}
|
||||
|
||||
UIView *hitChild = [node hitTest: point withEvent:event withTransform:matrix];
|
||||
UIView *hitChild = [node hitTest:transformed withEvent:event];
|
||||
|
||||
if (hitChild) {
|
||||
node.active = YES;
|
||||
return (node.responsible || (node != hitChild)) ? hitChild : self;
|
||||
}
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
NSMutableDictionary<NSString *, RNSVGNode *> *_templates;
|
||||
NSMutableDictionary<NSString *, RNSVGPainter *> *_painters;
|
||||
CGAffineTransform _viewBoxTransform;
|
||||
CGAffineTransform _invviewBoxTransform;
|
||||
}
|
||||
|
||||
- (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex
|
||||
@@ -129,6 +130,7 @@
|
||||
eRect:rect
|
||||
align:self.align
|
||||
meetOrSlice:self.meetOrSlice];
|
||||
_invviewBoxTransform = CGAffineTransformInvert(_viewBoxTransform);
|
||||
CGContextConcatCTM(context, _viewBoxTransform);
|
||||
}
|
||||
|
||||
@@ -167,6 +169,7 @@
|
||||
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
|
||||
{
|
||||
if (self.align) {
|
||||
CGPoint transformed = CGPointApplyAffineTransform(point, _invviewBoxTransform);
|
||||
for (RNSVGNode *node in [self.subviews reverseObjectEnumerator]) {
|
||||
if (![node isKindOfClass:[RNSVGNode class]]) {
|
||||
continue;
|
||||
@@ -178,7 +181,7 @@
|
||||
return node;
|
||||
}
|
||||
|
||||
UIView *hitChild = [node hitTest: point withEvent:event withTransform:_viewBoxTransform];
|
||||
UIView *hitChild = [node hitTest:transformed withEvent:event];
|
||||
|
||||
if (hitChild) {
|
||||
node.active = YES;
|
||||
|
||||
Reference in New Issue
Block a user