diff --git a/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm b/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm index ecdc55569..d9e55caf1 100644 --- a/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm +++ b/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm @@ -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 diff --git a/ReactCommon/fabric/attributedstring/AttributedString.cpp b/ReactCommon/fabric/attributedstring/AttributedString.cpp index b5eb74af1..094b28ed0 100644 --- a/ReactCommon/fabric/attributedstring/AttributedString.cpp +++ b/ReactCommon/fabric/attributedstring/AttributedString.cpp @@ -39,6 +39,14 @@ const std::vector &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 { diff --git a/ReactCommon/fabric/attributedstring/AttributedString.h b/ReactCommon/fabric/attributedstring/AttributedString.h index 4fa5ac9b4..560560ceb 100644 --- a/ReactCommon/fabric/attributedstring/AttributedString.h +++ b/ReactCommon/fabric/attributedstring/AttributedString.h @@ -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;