-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Added attributed versions of accessibilityLabel, accessibilityHint, accessibilityValue #554
Changes from 7 commits
54ebd6f
fb89130
f0e48fc
1677568
c43f7de
b0a5dc1
254637a
7505168
9da8544
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -873,10 +873,20 @@ - (void)setSemanticContentAttribute:(UISemanticContentAttribute)semanticContentA | |
(_view ? _view.viewAndPendingViewStateProperty : nodeProperty )\ | ||
: ASDisplayNodeGetPendingState(self).viewAndPendingViewStateProperty | ||
|
||
// Attributed version of `_getAccessibilityFromViewOrProperty` macro | ||
#define _getAttributedAccessibilityFromViewOrProperty(nodeProperty, viewAndPendingViewStatePropertyKey) __loaded(self) ? \ | ||
(_view ? (NSAttributedString *)[_view valueForKey: viewAndPendingViewStatePropertyKey] : nodeProperty )\ | ||
: (NSAttributedString *)[ASDisplayNodeGetPendingState(self) valueForKey: viewAndPendingViewStatePropertyKey] | ||
|
||
// Helper function to set property values on pending state or view and property if loaded | ||
#define _setAccessibilityToViewAndProperty(nodeProperty, nodeValueExpr, viewAndPendingViewStateProperty, viewAndPendingViewStateExpr) \ | ||
nodeProperty = nodeValueExpr; _setToViewOnly(viewAndPendingViewStateProperty, viewAndPendingViewStateExpr) | ||
|
||
// Attributed version of `_setAccessibilityToViewAndProperty` macro | ||
#define _setAttributedAccessibilityToViewAndProperty(nodeProperty, nodeValueExpr, viewAndPendingViewStatePropertyKey, viewAndPendingViewStateExpr) \ | ||
nodeProperty = nodeValueExpr; BOOL shouldApply = ASDisplayNodeShouldApplyBridgedWriteToView(self); \ | ||
if (shouldApply) { [_view setValue:(viewAndPendingViewStateExpr) forKey: viewAndPendingViewStatePropertyKey]; } else { [ASDisplayNodeGetPendingState(self) setValue:(viewAndPendingViewStateExpr) forKey:viewAndPendingViewStatePropertyKey]; } | ||
|
||
@implementation ASDisplayNode (UIViewBridgeAccessibility) | ||
|
||
- (BOOL)isAccessibilityElement | ||
|
@@ -901,6 +911,28 @@ - (void)setAccessibilityLabel:(NSString *)accessibilityLabel | |
{ | ||
_bridge_prologue_write; | ||
_setAccessibilityToViewAndProperty(_accessibilityLabel, accessibilityLabel, accessibilityLabel, accessibilityLabel); | ||
if (AS_AT_LEAST_IOS11) { | ||
_accessibilityAttributedLabel = [[NSAttributedString alloc] initWithString:accessibilityLabel]; | ||
BOOL shouldApply = ASDisplayNodeShouldApplyBridgedWriteToView(self); | ||
if (shouldApply) { | ||
[_view setValue: [[NSAttributedString alloc] initWithString:accessibilityLabel] forKey:@"accessibilityAttributedLabel"]; | ||
} else { | ||
[ASDisplayNodeGetPendingState(self) setValue: [[NSAttributedString alloc] initWithString:accessibilityLabel] forKey:@"accessibilityAttributedLabel"]; | ||
} | ||
} | ||
} | ||
|
||
- (NSAttributedString *)accessibilityAttributedLabel | ||
{ | ||
_bridge_prologue_read; | ||
return _getAttributedAccessibilityFromViewOrProperty(_accessibilityAttributedLabel, @"accessibilityAttributedLabel"); | ||
} | ||
|
||
- (void)setAccessibilityAttributedLabel:(NSAttributedString *)accessibilityAttributedLabel | ||
{ | ||
_bridge_prologue_write; | ||
{ _setAttributedAccessibilityToViewAndProperty(_accessibilityAttributedLabel, accessibilityAttributedLabel, @"accessibilityAttributedLabel", accessibilityAttributedLabel); } | ||
{ _setAttributedAccessibilityToViewAndProperty(_accessibilityLabel, accessibilityAttributedLabel.string, @"accessibilityLabel", accessibilityAttributedLabel.string); } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, I wonder if one of the tests should have caught that. But you're definitely right! |
||
} | ||
|
||
- (NSString *)accessibilityHint | ||
|
@@ -913,6 +945,22 @@ - (void)setAccessibilityHint:(NSString *)accessibilityHint | |
{ | ||
_bridge_prologue_write; | ||
_setAccessibilityToViewAndProperty(_accessibilityHint, accessibilityHint, accessibilityHint, accessibilityHint); | ||
if (AS_AT_LEAST_IOS11) { | ||
_setAttributedAccessibilityToViewAndProperty(_accessibilityAttributedHint, [[NSAttributedString alloc] initWithString:accessibilityHint], @"accessibilityAttributedHint", [[NSAttributedString alloc] initWithString:accessibilityHint]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: For readability and a tiny perf win, cache |
||
} | ||
} | ||
|
||
- (NSAttributedString *)accessibilityAttributedHint | ||
{ | ||
_bridge_prologue_read; | ||
return _getAttributedAccessibilityFromViewOrProperty(_accessibilityAttributedHint, @"accessibilityAttributedHint"); | ||
} | ||
|
||
- (void)setAccessibilityAttributedHint:(NSAttributedString *)accessibilityAttributedHint | ||
{ | ||
_bridge_prologue_write; | ||
{ _setAttributedAccessibilityToViewAndProperty(_accessibilityAttributedHint, accessibilityAttributedHint, @"accessibilityAttributedHint", accessibilityAttributedHint); } | ||
{ _setAttributedAccessibilityToViewAndProperty(_accessibilityHint, accessibilityAttributedHint.string, @"accessibilityHint", accessibilityAttributedHint.string); } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, use |
||
} | ||
|
||
- (NSString *)accessibilityValue | ||
|
@@ -925,6 +973,22 @@ - (void)setAccessibilityValue:(NSString *)accessibilityValue | |
{ | ||
_bridge_prologue_write; | ||
_setAccessibilityToViewAndProperty(_accessibilityValue, accessibilityValue, accessibilityValue, accessibilityValue); | ||
if (AS_AT_LEAST_IOS11) { | ||
_setAttributedAccessibilityToViewAndProperty(_accessibilityAttributedValue, [[NSAttributedString alloc] initWithString:accessibilityValue], @"accessibilityAttributedValue", [[NSAttributedString alloc] initWithString:accessibilityValue]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Same here, cache the attributed string. |
||
} | ||
} | ||
|
||
- (NSAttributedString *)accessibilityAttributedValue | ||
{ | ||
_bridge_prologue_read; | ||
return _getAttributedAccessibilityFromViewOrProperty(_accessibilityAttributedValue, @"accessibilityAttributedValue"); | ||
} | ||
|
||
- (void)setAccessibilityAttributedValue:(NSAttributedString *)accessibilityAttributedValue | ||
{ | ||
_bridge_prologue_write; | ||
{ _setAttributedAccessibilityToViewAndProperty(_accessibilityAttributedValue, accessibilityAttributedValue, @"accessibilityAttributedValue", accessibilityAttributedValue); } | ||
{ _setAttributedAccessibilityToViewAndProperty(_accessibilityValue, accessibilityAttributedValue.string, @"accessibilityValue", accessibilityAttributedValue.string); } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
} | ||
|
||
- (UIAccessibilityTraits)accessibilityTraits | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
_setAttributedAccessibilityToViewAndProperty
here?