Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow custom attributedTextWithBaseTextAttributes in RCTBaseTextShadowView subclasses #25283

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Libraries/Text/BaseText/RCTBaseTextShadowView.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ NS_ASSUME_NONNULL_BEGIN

extern NSString *const RCTBaseTextShadowViewEmbeddedShadowViewAttributeName;

@interface RCTBaseTextShadowView : RCTShadowView
@interface RCTBaseTextShadowView : RCTShadowView {
@protected NSAttributedString *_Nullable cachedAttributedText;
@protected RCTTextAttributes *_Nullable cachedTextAttributes;
}

@property (nonatomic, strong) RCTTextAttributes *textAttributes;

Expand Down
18 changes: 7 additions & 11 deletions Libraries/Text/BaseText/RCTBaseTextShadowView.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ static void RCTInlineViewYogaNodeDirtied(YGNodeRef node)
}

@implementation RCTBaseTextShadowView
{
NSAttributedString *_Nullable _cachedAttributedText;
RCTTextAttributes *_Nullable _cachedTextAttributes;
}

- (instancetype)init
{
Expand Down Expand Up @@ -86,8 +82,8 @@ - (NSAttributedString *)attributedTextWithBaseTextAttributes:(nullable RCTTextAt
textAttributes = [self.textAttributes copy];
}

if (_cachedAttributedText && [_cachedTextAttributes isEqual:textAttributes]) {
return _cachedAttributedText;
if (cachedAttributedText && [cachedTextAttributes isEqual:textAttributes]) {
return cachedAttributedText;
}

NSMutableAttributedString *attributedText = [NSMutableAttributedString new];
Expand Down Expand Up @@ -133,17 +129,17 @@ - (NSAttributedString *)attributedTextWithBaseTextAttributes:(nullable RCTTextAt

[self clearLayout];

_cachedAttributedText = [attributedText copy];
_cachedTextAttributes = textAttributes;
cachedAttributedText = [attributedText copy];
cachedTextAttributes = textAttributes;

return _cachedAttributedText;
return cachedAttributedText;
}

- (void)dirtyLayout
{
[super dirtyLayout];
_cachedAttributedText = nil;
_cachedTextAttributes = nil;
cachedAttributedText = nil;
cachedTextAttributes = nil;
}

- (void)didUpdateReactSubviews
Expand Down