mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-06 00:12:21 +00:00
run hitTest only if necessary
This commit is contained in:
@@ -11,9 +11,12 @@
|
||||
#import "RNSVGContainer.h"
|
||||
#import "RNSVGNode.h"
|
||||
#import "RNSVGCGFCRule.h"
|
||||
#import "RNSVGSvgView.h"
|
||||
|
||||
@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;
|
||||
- (RNSVGSvgView *)getSvgView;
|
||||
|
||||
@end
|
||||
|
||||
@@ -13,9 +13,15 @@
|
||||
- (void)renderLayerTo:(CGContextRef)context
|
||||
{
|
||||
if (self.asClipPath == NULL) {
|
||||
RNSVGSvgView* svg = [self getSvgView];
|
||||
[self clip:context];
|
||||
|
||||
for (RNSVGNode *node in self.subviews) {
|
||||
[node renderTo:context];
|
||||
|
||||
if (node.touchable && !svg.touchable) {
|
||||
self.touchable = YES;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
[self defineClipPath:[self getPath:context] clipPathId:self.asClipPath];
|
||||
@@ -29,7 +35,6 @@
|
||||
CGAffineTransform transform = node.transform;
|
||||
CGPathAddPath(path, &transform, [node getPath:context]);
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
@@ -39,7 +44,6 @@
|
||||
{
|
||||
for (RNSVGNode *node in [self.subviews reverseObjectEnumerator]) {
|
||||
UIView *view = [node hitTest: point withEvent:event];
|
||||
|
||||
if (view != NULL) {
|
||||
return view;
|
||||
}
|
||||
@@ -47,4 +51,14 @@
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (RNSVGSvgView *)getSvgView
|
||||
{
|
||||
UIView *parent = self.superview;
|
||||
while ([parent class] != [RNSVGSvgView class]) {
|
||||
parent = parent.superview;
|
||||
}
|
||||
|
||||
return (RNSVGSvgView *)parent;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -11,4 +11,7 @@
|
||||
#import "RNSVGContainer.h"
|
||||
|
||||
@interface RNSVGSvgView : UIView <RNSVGContainer>
|
||||
|
||||
@property (nonatomic, assign) BOOL touchable;
|
||||
|
||||
@end
|
||||
|
||||
@@ -21,8 +21,13 @@
|
||||
- (void)drawRect:(CGRect)rect
|
||||
{
|
||||
CGContextRef context = UIGraphicsGetCurrentContext();
|
||||
|
||||
for (RNSVGNode *node in self.subviews) {
|
||||
[node renderTo:context];
|
||||
|
||||
if (node.touchable && !self.touchable) {
|
||||
self.touchable = YES;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,4 +36,9 @@
|
||||
self.backgroundColor = inheritedBackgroundColor;
|
||||
}
|
||||
|
||||
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
|
||||
{
|
||||
return self.touchable ? [super hitTest:point withEvent:event] : nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
@property (nonatomic, assign) RNSVGCGFCRule clipRule;
|
||||
@property (nonatomic, assign) CGPathRef clipPath; // convert clipPath="M0,0 L0,10 L10,10z" into path
|
||||
@property (nonatomic, strong) NSString *clipPathId; // use clipPath="url(#clip)" as ClipPath
|
||||
@property (nonatomic, assign) BOOL touchable;
|
||||
|
||||
- (void)invalidate;
|
||||
- (void)renderTo:(CGContextRef)context;
|
||||
@@ -53,4 +54,5 @@
|
||||
|
||||
|
||||
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event;
|
||||
|
||||
@end
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
*/
|
||||
|
||||
#import "RNSVGNode.h"
|
||||
|
||||
#import "RNSVGContainer.h"
|
||||
|
||||
static NSMutableDictionary *ClipPaths;
|
||||
|
||||
@@ -32,5 +32,6 @@ RCT_EXPORT_MODULE()
|
||||
RCT_EXPORT_VIEW_PROPERTY(opacity, CGFloat)
|
||||
RCT_EXPORT_VIEW_PROPERTY(trans, CGAffineTransform)
|
||||
RCT_EXPORT_VIEW_PROPERTY(clipPathId, NSString)
|
||||
RCT_EXPORT_VIEW_PROPERTY(touchable, BOOL)
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user