diff --git a/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.h b/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.h index 23aa0a0b4ba..164a1c8c2e8 100644 --- a/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.h +++ b/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.h @@ -11,11 +11,17 @@ NS_ASSUME_NONNULL_BEGIN -/** +/* * UIView class for component. */ @interface RCTParagraphComponentView : RCTViewComponentView +/* + * Returns an `NSAttributedString` representing the content of the component. + * To be only used by external introspection and debug tools. + */ +@property (nonatomic, nullable, readonly) NSAttributedString *attributedText; + @end NS_ASSUME_NONNULL_END diff --git a/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm b/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm index 2b3cc1f6cf5..faaeb73736d 100644 --- a/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm +++ b/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm @@ -13,6 +13,7 @@ #import #import #import +#import #import #import #import @@ -41,6 +42,27 @@ using namespace facebook::react; return self; } +- (NSString *)description +{ + NSString *superDescription = [super description]; + + // Cutting the last `>` character. + if (superDescription.length > 0 && [superDescription characterAtIndex:superDescription.length - 1] == '>') { + superDescription = [superDescription substringToIndex:superDescription.length - 1]; + } + + return [NSString stringWithFormat:@"%@; attributedText = %@>", superDescription, self.attributedText]; +} + +- (NSAttributedString *_Nullable)attributedText +{ + if (!_state) { + return nil; + } + + return RCTNSAttributedStringFromAttributedString(_state->getData().attributedString); +} + #pragma mark - RCTComponentViewProtocol + (ComponentDescriptorProvider)componentDescriptorProvider