Skip to content

Commit

Permalink
Fix ASTextNode2 supportsLayerBacking (#1545)
Browse files Browse the repository at this point in the history
`[NSAttributedString enumerateAttribute:inRange:options:usingBlock]` can be called multiple times with a value of nil. The current logic didn't consider this to find out if a links is present within the attributed string.
  • Loading branch information
maicki authored and Adlai-Holler committed Jun 25, 2019
1 parent a11c084 commit d7239ba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Source/ASTextNode2.mm
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,10 @@ - (BOOL)supportsLayerBacking
for (NSString *linkAttributeName in _linkAttributeNames) {
__block BOOL hasLink = NO;
[attributedText enumerateAttribute:linkAttributeName inRange:range options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
hasLink = (value != nil);
if (value == nil) {
return;
}
hasLink = YES;
*stop = YES;
}];
if (hasLink) {
Expand Down
14 changes: 14 additions & 0 deletions Tests/ASTextNode2Tests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,18 @@ - (void)testRespectingAccessibilitySetting
XCTAssertFalse(accessibleTextNode.isAccessibilityElement);
}

- (void)testSupportsLayerBacking
{
ASTextNode2 *textNode = [[ASTextNode2 alloc] init];
textNode.attributedText = [[NSAttributedString alloc] initWithString:@"new string"];
XCTAssertTrue(textNode.supportsLayerBacking);

NSString *link = @"https://texturegroup.com";
NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"Texture Website: %@", link]];
NSRange linkRange = [attributedText.string rangeOfString:link];
[attributedText addAttribute:NSLinkAttributeName value:link range:linkRange];
textNode.attributedText = attributedText;
XCTAssertFalse(textNode.supportsLayerBacking);
}

@end

0 comments on commit d7239ba

Please sign in to comment.