mirror of
https://github.com/TextureGroup/Texture.git
synced 2026-04-07 19:17:39 +00:00
[ASTextNode] Maintain isAccessibilityElement setting on text nodes when updating text (#1326)
This commit is contained in:
+10
-1
@@ -464,12 +464,16 @@ static NSArray *DefaultLinkAttributeNames() {
|
||||
attributedText = [[NSAttributedString alloc] initWithString:@"" attributes:nil];
|
||||
}
|
||||
|
||||
NSAttributedString *oldAttributedText = nil;
|
||||
|
||||
{
|
||||
ASLockScopeSelf();
|
||||
if (ASObjectIsEqual(attributedText, _attributedText)) {
|
||||
return;
|
||||
}
|
||||
|
||||
oldAttributedText = _attributedText;
|
||||
|
||||
NSAttributedString *cleanedAttributedString = ASCleanseAttributedStringOfCoreTextAttributes(attributedText);
|
||||
|
||||
// Invalidating the truncation text must be done while we still hold the lock. Because after we release it,
|
||||
@@ -498,7 +502,12 @@ static NSArray *DefaultLinkAttributeNames() {
|
||||
// Accessiblity
|
||||
const auto currentAttributedText = self.attributedText; // Grab attributed string again in case it changed in the meantime
|
||||
self.accessibilityLabel = self.defaultAccessibilityLabel;
|
||||
self.isAccessibilityElement = (currentAttributedText.length != 0); // We're an accessibility element by default if there is a string.
|
||||
|
||||
// We update the isAccessibilityElement setting if this node is not switching between strings.
|
||||
if (oldAttributedText.length == 0 || currentAttributedText.length == 0) {
|
||||
// We're an accessibility element by default if there is a string.
|
||||
self.isAccessibilityElement = (currentAttributedText.length != 0);
|
||||
}
|
||||
|
||||
#if AS_TEXTNODE_RECORD_ATTRIBUTED_STRINGS
|
||||
[ASTextNode _registerAttributedText:_attributedText];
|
||||
|
||||
@@ -396,6 +396,7 @@ static NSArray *DefaultLinkAttributeNames() {
|
||||
// Holding it for the duration of the method is more efficient in this case.
|
||||
ASLockScopeSelf();
|
||||
|
||||
NSAttributedString *oldAttributedText = _attributedText;
|
||||
if (!ASCompareAssignCopy(_attributedText, attributedText)) {
|
||||
return;
|
||||
}
|
||||
@@ -418,7 +419,12 @@ static NSArray *DefaultLinkAttributeNames() {
|
||||
|
||||
// Accessiblity
|
||||
self.accessibilityLabel = self.defaultAccessibilityLabel;
|
||||
self.isAccessibilityElement = (length != 0); // We're an accessibility element by default if there is a string.
|
||||
|
||||
// We update the isAccessibilityElement setting if this node is not switching between strings.
|
||||
if (oldAttributedText.length == 0 || length == 0) {
|
||||
// We're an accessibility element by default if there is a string.
|
||||
self.isAccessibilityElement = (length != 0);
|
||||
}
|
||||
|
||||
#if AS_TEXTNODE2_RECORD_ATTRIBUTED_STRINGS
|
||||
[ASTextNode _registerAttributedText:_attributedText];
|
||||
|
||||
@@ -91,4 +91,20 @@
|
||||
_textNode.defaultAccessibilityLabel, _attributedText.string);
|
||||
}
|
||||
|
||||
- (void)testRespectingAccessibilitySetting
|
||||
{
|
||||
ASTextNode2 *textNode = [[ASTextNode2 alloc] init];
|
||||
textNode.attributedText = _attributedText;
|
||||
textNode.isAccessibilityElement = NO;
|
||||
|
||||
textNode.attributedText = [[NSAttributedString alloc] initWithString:@"new string"];
|
||||
XCTAssertFalse(textNode.isAccessibilityElement);
|
||||
|
||||
// Ensure removing string on an accessible text node updates the setting.
|
||||
ASTextNode2 *accessibleTextNode = [ASTextNode2 new];
|
||||
accessibleTextNode.attributedText = _attributedText;
|
||||
accessibleTextNode.attributedText = nil;
|
||||
XCTAssertFalse(accessibleTextNode.isAccessibilityElement);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -175,6 +175,23 @@
|
||||
XCTAssertTrue([_textNode.accessibilityLabel isEqualToString:_attributedText.string], @"Accessibility label is incorrectly set to \n%@\n when it should be \n%@\n", _textNode.accessibilityLabel, _attributedText.string);
|
||||
}
|
||||
|
||||
- (void)testRespectingAccessibilitySetting
|
||||
{
|
||||
ASTextNode *textNode = [ASTextNode new];
|
||||
|
||||
textNode.attributedText = _attributedText;
|
||||
textNode.isAccessibilityElement = NO;
|
||||
|
||||
textNode.attributedText = [[NSAttributedString alloc] initWithString:@"new string"];
|
||||
XCTAssertFalse(textNode.isAccessibilityElement);
|
||||
|
||||
// Ensure removing string on an accessible text node updates the setting.
|
||||
ASTextNode *accessibleTextNode = [ASTextNode new];
|
||||
accessibleTextNode.attributedText = _attributedText;
|
||||
accessibleTextNode.attributedText = nil;
|
||||
XCTAssertFalse(accessibleTextNode.isAccessibilityElement);
|
||||
}
|
||||
|
||||
- (void)testLinkAttribute
|
||||
{
|
||||
NSString *linkAttributeName = @"MockLinkAttributeName";
|
||||
|
||||
Reference in New Issue
Block a user