Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes accessibilityLabel bug on ASButtonNode that has no title #1573

Merged
merged 2 commits into from
Jul 11, 2019

Conversation

SterlingWaves
Copy link
Contributor

We use the ASButtonNode as a pure icon button that has no title, and I also give this button an accessibility label. Since this buttton's titleNode will be non-nil if the self.titleNode getter is ever called, my accessibility label will get reset to empty string every time the button's state changes (selected, enabled, etc.). However, I'd like my button's accessibility label to remain consistent in this case. This PR addresses this problem, i.e. if the button title and the new title are both either empty or nil, we do not reset the accessibility label. Also added corresponding test.

@CLAassistant
Copy link

CLAassistant commented Jul 9, 2019

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@nguyenhuy nguyenhuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@nguyenhuy
Copy link
Member

@maicki Can you take a look at this one when you have time?

@maicki
Copy link
Contributor

maicki commented Jul 10, 2019

I think we should change the logic a bit, the if clause is really hard to read. And I also think we don't need to call the setter not before within the if clause:

NSAttributedString *attributedString = _titleNode.attributedText;
if ((attributedString.length > 0 || newTitle.length > 0) && [attributedString isEqualToAttributedString:newTitle] == NO) {
  // Calling self.titleNode is essential here because _titleNode is lazily created by the getter.   
  self.titleNode.attributedText = newTitle;
  [self unlock];
    
  self.accessibilityLabel = self.defaultAccessibilityLabel;
  [self updateYogaLayoutIfNeeded];
  [self setNeedsLayout];
  return;
}

Also @SterlingWaves would you mind adding this ASButtonNode unit test:

- (void)testUpdateTitle
{
  NSAttributedString *title = [[NSAttributedString alloc] initWithString:@"MyTitle"];
  ASButtonNode *buttonNode = [[ASButtonNode alloc] init];
  [buttonNode setAttributedTitle:title forState:UIControlStateNormal];
  XCTAssertTrue([[buttonNode attributedTitleForState:UIControlStateNormal] isEqualToAttributedString:title]);
  XCTAssert([buttonNode.titleNode.attributedText isEqualToAttributedString:title]);
}

@nguyenhuy Thoughts?

@nguyenhuy
Copy link
Member

Yeah, agree with your suggestions, @maicki.

@SterlingPinterest
Copy link

@maicki @nguyenhuy updated.

@nguyenhuy
Copy link
Member

Thanks @SterlingPinterest. I assume @maicki would approve this PR so I'm gonna go ahead and merge it.

@nguyenhuy nguyenhuy merged commit 901f4dd into TextureGroup:master Jul 11, 2019
Copy link
Contributor

@maicki maicki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, yes seems fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants