Skip to content

Commit

Permalink
fix(ios): #1290 pointerEvents="none" gesture handling
Browse files Browse the repository at this point in the history
  • Loading branch information
msand committed Mar 5, 2020
1 parent bd78998 commit 11d14fd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
7 changes: 7 additions & 0 deletions ios/RNSVGNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

#import <React/UIView+React.h>
#import <React/RCTPointerEvents.h>
#import "RNSVGCGFCRule.h"
#import "RNSVGSvgView.h"
@class RNSVGGroup;
Expand Down Expand Up @@ -35,7 +36,13 @@ extern CGFloat const RNSVG_DEFAULT_FONT_SIZE;
@property (nonatomic, strong) NSString *markerStart;
@property (nonatomic, strong) NSString *markerMid;
@property (nonatomic, strong) NSString *markerEnd;

/**
* Used to control how touch events are processed.
*/
@property (nonatomic, assign) RCTPointerEvents pointerEvents;
@property (nonatomic, assign) BOOL responsible;

@property (nonatomic, assign) CGAffineTransform ctm;
@property (nonatomic, assign) CGAffineTransform screenCTM;
@property (nonatomic, assign) CGAffineTransform matrix;
Expand Down
9 changes: 9 additions & 0 deletions ios/RNSVGNode.m
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ - (void)reactSetInheritedBackgroundColor:(UIColor *)inheritedBackgroundColor
self.backgroundColor = inheritedBackgroundColor;
}

- (void)setPointerEvents:(RCTPointerEvents)pointerEvents
{
_pointerEvents = pointerEvents;
self.userInteractionEnabled = (pointerEvents != RCTPointerEventsNone);
if (pointerEvents == RCTPointerEventsBoxNone) {
self.accessibilityViewIsModal = NO;
}
}

- (void)setName:(NSString *)name
{
if ([name isEqualToString:_name]) {
Expand Down
3 changes: 2 additions & 1 deletion ios/RNSVGRenderable.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* LICENSE file in the root directory of this source tree.
*/

#import <React/RCTPointerEvents.h>
#import "RNSVGRenderable.h"
#import "RNSVGClipPath.h"
#import "RNSVGMask.h"
Expand Down Expand Up @@ -518,7 +519,7 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
return nil;
}

BOOL canReceiveTouchEvents = (([self isUserInteractionEnabled] || self.responsible) && ![self isHidden]);
BOOL canReceiveTouchEvents = (self.pointerEvents != RCTPointerEventsNone && ![self isHidden]);
if(!canReceiveTouchEvents) {
return nil;
}
Expand Down
25 changes: 2 additions & 23 deletions ios/ViewManagers/RNSVGNodeManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -238,28 +238,7 @@ - (UIView *)view

RCT_CUSTOM_VIEW_PROPERTY(pointerEvents, RCTPointerEvents, RNSVGNode)
{
if (!json) {
view.userInteractionEnabled = defaultView.userInteractionEnabled;
return;
}

switch ([RCTConvert RCTPointerEvents:json]) {
case RCTPointerEventsBoxNone:
case RCTPointerEventsBoxOnly:
case RCTPointerEventsUnspecified:
// Pointer events "unspecified" acts as if a stylesheet had not specified,
// which is different than "auto" in CSS (which cannot and will not be
// supported in `React`. "auto" may override a parent's "none".
// Unspecified values do not.
// This wouldn't override a container view's `userInteractionEnabled = NO`
view.userInteractionEnabled = YES;
break;
case RCTPointerEventsNone:
view.userInteractionEnabled = NO;
break;
default:
view.userInteractionEnabled = NO;
RCTLogError(@"UIView base class does not support pointerEvent value: %@", json);
}
view.pointerEvents = json ? [RCTConvert RCTPointerEvents:json] : defaultView.pointerEvents;
}

@end

0 comments on commit 11d14fd

Please sign in to comment.