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
This commit is contained in:
Valentin Shergin
2020-03-18 19:06:54 -07:00
committed by Facebook GitHub Bot
parent 652fa1b8d4
commit ad34c63d9e
2 changed files with 29 additions and 1 deletions
@@ -11,11 +11,17 @@
NS_ASSUME_NONNULL_BEGIN
/**
/*
* UIView class for <Paragraph> 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
@@ -13,6 +13,7 @@
#import <react/components/text/RawTextComponentDescriptor.h>
#import <react/components/text/TextComponentDescriptor.h>
#import <react/graphics/Geometry.h>
#import <react/textlayoutmanager/RCTAttributedTextUtils.h>
#import <react/textlayoutmanager/RCTTextLayoutManager.h>
#import <react/textlayoutmanager/TextLayoutManager.h>
#import <react/utils/ManagedObjectWrapper.h>
@@ -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