From f44c82956440bceb62d99e92085b2efb41193555 Mon Sep 17 00:00:00 2001 From: Scott Goodson Date: Wed, 16 Dec 2015 17:20:08 -0800 Subject: [PATCH] ASTextNode shouldn't create a long press gesture recognizer unless the delegate cares about the callback. --- AsyncDisplayKit/ASTextNode.h | 5 +++++ AsyncDisplayKit/ASTextNode.mm | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/AsyncDisplayKit/ASTextNode.h b/AsyncDisplayKit/ASTextNode.h index db66b09e13..1a47f3d730 100644 --- a/AsyncDisplayKit/ASTextNode.h +++ b/AsyncDisplayKit/ASTextNode.h @@ -194,6 +194,9 @@ typedef NS_ENUM(NSUInteger, ASTextNodeHighlightStyle) { /** @abstract Responds to actions from links in the text node. + @discussion The delegate must be set before the node is loaded, and implement + textNode:longPressedLinkAttribute:value:atPoint:textRange: in order for + the long press gesture recognizer to be installed. */ @property (nonatomic, weak) id delegate; @@ -233,6 +236,8 @@ typedef NS_ENUM(NSUInteger, ASTextNodeHighlightStyle) { @param value The value of the tapped attribute. @param point The point within textNode, in textNode's coordinate system, that was tapped. @param textRange The range of highlighted text. + @discussion In addition to implementing this method, the delegate must be set on the text + node before it is loaded (the recognizer is created in -didLoad) */ - (void)textNode:(ASTextNode *)textNode longPressedLinkAttribute:(NSString *)attribute value:(id)value atPoint:(CGPoint)point textRange:(NSRange)textRange; diff --git a/AsyncDisplayKit/ASTextNode.mm b/AsyncDisplayKit/ASTextNode.mm index 315638093f..e4a0e09e1c 100644 --- a/AsyncDisplayKit/ASTextNode.mm +++ b/AsyncDisplayKit/ASTextNode.mm @@ -211,8 +211,9 @@ static NSString *ASTextNodeTruncationTokenAttributeName = @"ASTextNodeTruncation { [super didLoad]; - // If we are view-backed, support gesture interaction. - if (!self.isLayerBacked) { + // If we are view-backed and the delegate cares, support the long-press callback. + SEL longPressCallback = @selector(textNode:longPressedLinkAttribute:value:atPoint:textRange:); + if (!self.isLayerBacked && [self.delegate respondsToSelector:longPressCallback]) { _longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(_handleLongPress:)]; _longPressGestureRecognizer.cancelsTouchesInView = self.longPressCancelsTouches; _longPressGestureRecognizer.delegate = self;