Skip to content

Commit

Permalink
Fabric: Exposing RCTParagraphComponentView::attributedText
Browse files Browse the repository at this point in the history
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
  • Loading branch information
shergin authored and facebook-github-bot committed Mar 19, 2020
1 parent 652fa1b commit ad34c63
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -41,6 +42,27 @@ - (instancetype)initWithFrame:(CGRect)frame
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
Expand Down

0 comments on commit ad34c63

Please sign in to comment.