mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-05-26 12:29:10 +00:00
fix touch system on iOS
subViews in G will run hitTest now. fix hitTest while using clipPath
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
@@ -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);
|
||||
|
||||
@@ -25,4 +25,6 @@
|
||||
@property (nonatomic, assign) CGFloat strokeDashoffset;
|
||||
@property (nonatomic, assign) CGMutablePathRef nodeArea;
|
||||
|
||||
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event;
|
||||
|
||||
@end
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user