Fabric: Propper support for `accessibilityLabel` in RCTParagraphComponentView

Summary:
@public
This approach is basically copying exising implementation that we have in RCTTextView (D5806097).
Changes in `AttributedString` is quite trivial.

Reviewed By: mdvacca

Differential Revision: D8740000

fbshipit-source-id: 276afdf93d777f7ccb99ca8ee5a18a880de2acbf
This commit is contained in:
Valentin Shergin 2018-07-17 17:51:17 -07:00 committed by Facebook Github Bot
parent c68c3a53d4
commit 732c3a4f4e
3 changed files with 29 additions and 0 deletions

View File

@ -68,4 +68,20 @@ using namespace facebook::react;
frame:frame];
}
#pragma mark - Accessibility
- (NSString *)accessibilityLabel
{
NSString *superAccessibilityLabel = [super accessibilityLabel];
if (superAccessibilityLabel) {
return superAccessibilityLabel;
}
if (!_paragraphLocalData) {
return nil;
}
return RCTNSStringFromString(_paragraphLocalData->getAttributedString().getString());
}
@end

View File

@ -39,6 +39,14 @@ const std::vector<Fragment> &AttributedString::getFragments() const {
return fragments_;
}
std::string AttributedString::getString() const {
std::string string;
for (const auto &fragment : fragments_) {
string += fragment.string;
}
return string;
}
#pragma mark - DebugStringConvertible
SharedDebugStringConvertibleList AttributedString::getDebugChildren() const {

View File

@ -61,6 +61,11 @@ public:
*/
const Fragments &getFragments() const;
/*
* Returns a string constructed from all strings in all fragments.
*/
std::string getString() const;
#pragma mark - DebugStringConvertible
SharedDebugStringConvertibleList getDebugChildren() const override;