From ad34c63d9e395632da2ee28c5f33a2a8409ff663 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Wed, 18 Mar 2020 19:06:54 -0700 Subject: [PATCH] Fabric: Exposing `RCTParagraphComponentView::attributedText` Summary: The new prop on RCTParagraphComponentView is meant to be used only by external introspection tools, not the RN core. Changelog: [Internal] Fabric-specific internal change. Reviewed By: nscoding Differential Revision: D20523078 fbshipit-source-id: 4c457d070fd2c172d681c5aa7f731d2d52bba291 --- .../Text/RCTParagraphComponentView.h | 8 ++++++- .../Text/RCTParagraphComponentView.mm | 22 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) 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