Skip to content

Commit 06599b3

Browse files
Peter Arganyfacebook-github-bot
Peter Argany
authored andcommitted
Fix bug in iOS13 nested text rendering
Summary: This fixes a bug reported by Oculus and OSS. #26577 When rendering images nested in a `<Text/>` node, on the native side, `RCTTextShadowView` adds an empty NSTextAttachment to the attributed string to add some extra space. The image is then overlaid in the empty space . This all works fine and dandy on iOS12 and below. Starting in iOS13, an empty NSTextAttachment doesn't render as blank space. It renders as the "missing image" white page. When the real image is overlaid on the white page, it looks super broken. See github issue and test plan for examples. This fix is to assign an empty image to `NSTextAttachment`. I tried seeing if there was any other attribute we could use to just add white space to an attributed string, but this seems like the best one. Changelog: [iOS][Fixed] Fixed bug rendering nested text on iOS13 Reviewed By: xyin96 Differential Revision: D18048277 fbshipit-source-id: 711cee96934fc1937d694621a4417c152dde3a31
1 parent 2ea3304 commit 06599b3

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Libraries/Text/Text/RCTTextShadowView.m

+7
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ - (void)postprocessAttributedText:(NSMutableAttributedString *)attributedText
177177

178178
- (NSAttributedString *)attributedTextWithMeasuredAttachmentsThatFitSize:(CGSize)size
179179
{
180+
static UIImage *placeholderImage;
181+
static dispatch_once_t onceToken;
182+
dispatch_once(&onceToken, ^{
183+
placeholderImage = [UIImage new];
184+
});
185+
180186
NSMutableAttributedString *attributedText =
181187
[[NSMutableAttributedString alloc] initWithAttributedString:[self attributedTextWithBaseTextAttributes:nil]];
182188

@@ -195,6 +201,7 @@ - (NSAttributedString *)attributedTextWithMeasuredAttachmentsThatFitSize:(CGSize
195201
maximumSize:size];
196202
NSTextAttachment *attachment = [NSTextAttachment new];
197203
attachment.bounds = (CGRect){CGPointZero, fittingSize};
204+
attachment.image = placeholderImage;
198205
[attributedText addAttribute:NSAttachmentAttributeName value:attachment range:range];
199206
}
200207
];

0 commit comments

Comments
 (0)