Skip to content

Commit 6a96b7f

Browse files
authored
Merge pull request #4 from discordapp/bugfix/ios13-placeholder
placeholder image patch
2 parents 70e4882 + c6225ab commit 6a96b7f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Libraries/Text/Text/RCTTextShadowView.m

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,19 @@ - (void)postprocessAttributedText:(NSMutableAttributedString *)attributedText
168168
range:NSMakeRange(0, attributedText.length)];
169169
}
170170

171+
// iOS 13 attributed string attachments have placeholder images
172+
// https://github.com/facebook/react-native/pull/26653/files
173+
static UIImage *emptyImg = NULL;
174+
- (UIImage*)getEmptyImg
175+
{
176+
if (emptyImg == NULL) {
177+
UIGraphicsBeginImageContextWithOptions(CGSizeMake(1, 1), NO, 0);
178+
emptyImg = UIGraphicsGetImageFromCurrentImageContext();
179+
UIGraphicsEndImageContext();
180+
}
181+
return emptyImg;
182+
}
183+
171184
- (NSAttributedString *)attributedTextWithMeasuredAttachmentsThatFitSize:(CGSize)size
172185
{
173186
NSMutableAttributedString *attributedText =
@@ -188,6 +201,7 @@ - (NSAttributedString *)attributedTextWithMeasuredAttachmentsThatFitSize:(CGSize
188201
maximumSize:size];
189202
NSTextAttachment *attachment = [NSTextAttachment new];
190203
attachment.bounds = (CGRect){CGPointZero, fittingSize};
204+
[attachment setImage:[self getEmptyImg]];
191205
[attributedText addAttribute:NSAttachmentAttributeName value:attachment range:range];
192206
}
193207
];
@@ -297,7 +311,7 @@ - (void)layoutSubviewsWithContext:(RCTLayoutContext)layoutContext
297311
RCTRoundPixelValue(attachmentSize.width),
298312
RCTRoundPixelValue(attachmentSize.height)
299313
}};
300-
314+
301315
NSRange truncatedGlyphRange = [layoutManager truncatedGlyphRangeInLineFragmentForGlyphAtIndex:range.location];
302316
BOOL viewIsTruncated = NSIntersectionRange(range, truncatedGlyphRange).length != 0;
303317

0 commit comments

Comments
 (0)