Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AsyncDisplayKit/ASTextNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ typedef NS_ENUM(NSUInteger, ASTextNodeHighlightStyle) {
@param attribute The attribute that was tapped. Will not be nil.
@param value The value of the tapped attribute.
@param point The point within textNode, in textNode's coordinate system, that was touched to trigger a highlight.
@discussion If not implemented, the default value is NO.
@discussion If not implemented, the default value is YES.
@return YES if the entity attribute should be a link, NO otherwise.
*/
- (BOOL)textNode:(ASTextNode *)textNode shouldHighlightLinkAttribute:(NSString *)attribute value:(id)value atPoint:(CGPoint)point;
Expand Down
21 changes: 13 additions & 8 deletions AsyncDisplayKit/ASTextNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -394,13 +394,15 @@ - (id)linkAttributeValueAtPoint:(CGPoint)point
return [self _linkAttributeValueAtPoint:point
attributeName:attributeNameOut
range:rangeOut
inAdditionalTruncationMessage:NULL];
inAdditionalTruncationMessage:NULL
forHighlighting:NO];
}

- (id)_linkAttributeValueAtPoint:(CGPoint)point
attributeName:(out NSString **)attributeNameOut
range:(out NSRange *)rangeOut
inAdditionalTruncationMessage:(out BOOL *)inAdditionalTruncationMessageOut
forHighlighting:(BOOL)highlighting
{
ASTextKitRenderer *renderer = [self _renderer];
NSRange visibleRange = renderer.visibleRanges[0];
Expand Down Expand Up @@ -453,10 +455,10 @@ - (id)_linkAttributeValueAtPoint:(CGPoint)point
continue;
}

// Check if delegate implements optional method, if not assume NO.
// Should the text be highlightable/touchable?
if (![_delegate respondsToSelector:@selector(textNode:shouldHighlightLinkAttribute:value:atPoint:)] ||
![_delegate textNode:self shouldHighlightLinkAttribute:name value:value atPoint:point]) {
// If highlighting, check with delegate first. If not implemented, assume YES.
if (highlighting
&& [_delegate respondsToSelector:@selector(textNode:shouldHighlightLinkAttribute:value:atPoint:)]
&& ![_delegate textNode:self shouldHighlightLinkAttribute:name value:value atPoint:point]) {
value = nil;
name = nil;
}
Expand Down Expand Up @@ -758,7 +760,8 @@ -(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
id linkAttributeValue = [self _linkAttributeValueAtPoint:point
attributeName:&linkAttributeName
range:&range
inAdditionalTruncationMessage:&inAdditionalTruncationMessage];
inAdditionalTruncationMessage:&inAdditionalTruncationMessage
forHighlighting:YES];

NSUInteger lastCharIndex = NSIntegerMax;
BOOL linkCrossesVisibleRange = (lastCharIndex > range.location) && (lastCharIndex < NSMaxRange(range) - 1);
Expand Down Expand Up @@ -787,7 +790,8 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
id linkAttributeValue = [self _linkAttributeValueAtPoint:point
attributeName:&linkAttributeName
range:&range
inAdditionalTruncationMessage:&inAdditionalTruncationMessage];
inAdditionalTruncationMessage:&inAdditionalTruncationMessage
forHighlighting:YES];

NSUInteger lastCharIndex = NSIntegerMax;
BOOL linkCrossesVisibleRange = (lastCharIndex > range.location) && (lastCharIndex < NSMaxRange(range) - 1);
Expand Down Expand Up @@ -838,7 +842,8 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
[self _linkAttributeValueAtPoint:point
attributeName:NULL
range:&range
inAdditionalTruncationMessage:NULL];
inAdditionalTruncationMessage:NULL
forHighlighting:YES];

if (!NSEqualRanges(_highlightRange, range)) {
[self _clearHighlightIfNecessary];
Expand Down