From a0ec62b28261f431c29b2448d6fac66d2d666c13 Mon Sep 17 00:00:00 2001 From: Ethan Nagel Date: Mon, 27 Apr 2015 17:59:59 -0700 Subject: [PATCH] Add option to pass through touches to non-link text (disabled by default.) --- AsyncDisplayKit/ASTextNode.h | 5 +++++ AsyncDisplayKit/ASTextNode.mm | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/AsyncDisplayKit/ASTextNode.h b/AsyncDisplayKit/ASTextNode.h index 11fe337de0..c7ef7267e0 100644 --- a/AsyncDisplayKit/ASTextNode.h +++ b/AsyncDisplayKit/ASTextNode.h @@ -192,6 +192,11 @@ typedef NS_ENUM(NSUInteger, ASTextNodeHighlightStyle) { */ @property (nonatomic, assign) BOOL longPressCancelsTouches; +/** + @abstract if YES will not intercept touches for non-link areas of the text. Default is NO. + */ +@property (nonatomic, assign) BOOL passthroughNonlinkTouches; + @end diff --git a/AsyncDisplayKit/ASTextNode.mm b/AsyncDisplayKit/ASTextNode.mm index e631f9d28b..8a430ba45e 100644 --- a/AsyncDisplayKit/ASTextNode.mm +++ b/AsyncDisplayKit/ASTextNode.mm @@ -749,6 +749,33 @@ ASDISPLAYNODE_INLINE CGFloat ceilPixelValue(CGFloat f) #pragma mark - Touch Handling +-(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event +{ + if (!_passthroughNonlinkTouches) { + return [super pointInside:point withEvent:event]; + } + + NSRange range = NSMakeRange(0, 0); + NSString *linkAttributeName = nil; + BOOL inAdditionalTruncationMessage = NO; + + id linkAttributeValue = [self _linkAttributeValueAtPoint:point + attributeName:&linkAttributeName + range:&range + inAdditionalTruncationMessage:&inAdditionalTruncationMessage]; + + NSUInteger lastCharIndex = NSIntegerMax; + BOOL linkCrossesVisibleRange = (lastCharIndex > range.location) && (lastCharIndex < NSMaxRange(range) - 1); + + if (inAdditionalTruncationMessage) { + return YES; + } else if (range.length && !linkCrossesVisibleRange && linkAttributeValue != nil && linkAttributeName != nil) { + return YES; + } else { + return NO; + } +} + - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesBegan:touches withEvent:event];