From c6225ab03d1298ecfcece71dafa31a3aa23b763a Mon Sep 17 00:00:00 2001 From: Kyle Petrovich <1054402+fozzle@users.noreply.github.com> Date: Thu, 10 Oct 2019 16:33:57 -0700 Subject: [PATCH] palceholder image fix --- Libraries/Text/Text/RCTTextShadowView.m | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Libraries/Text/Text/RCTTextShadowView.m b/Libraries/Text/Text/RCTTextShadowView.m index d464e6ac75a411..eb03febb7fddb5 100644 --- a/Libraries/Text/Text/RCTTextShadowView.m +++ b/Libraries/Text/Text/RCTTextShadowView.m @@ -168,6 +168,19 @@ - (void)postprocessAttributedText:(NSMutableAttributedString *)attributedText range:NSMakeRange(0, attributedText.length)]; } +// iOS 13 attributed string attachments have placeholder images +// https://github.com/facebook/react-native/pull/26653/files +static UIImage *emptyImg = NULL; +- (UIImage*)getEmptyImg +{ + if (emptyImg == NULL) { + UIGraphicsBeginImageContextWithOptions(CGSizeMake(1, 1), NO, 0); + emptyImg = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + } + return emptyImg; +} + - (NSAttributedString *)attributedTextWithMeasuredAttachmentsThatFitSize:(CGSize)size { NSMutableAttributedString *attributedText = @@ -188,6 +201,7 @@ - (NSAttributedString *)attributedTextWithMeasuredAttachmentsThatFitSize:(CGSize maximumSize:size]; NSTextAttachment *attachment = [NSTextAttachment new]; attachment.bounds = (CGRect){CGPointZero, fittingSize}; + [attachment setImage:[self getEmptyImg]]; [attributedText addAttribute:NSAttachmentAttributeName value:attachment range:range]; } ]; @@ -297,7 +311,7 @@ - (void)layoutSubviewsWithContext:(RCTLayoutContext)layoutContext RCTRoundPixelValue(attachmentSize.width), RCTRoundPixelValue(attachmentSize.height) }}; - + NSRange truncatedGlyphRange = [layoutManager truncatedGlyphRangeInLineFragmentForGlyphAtIndex:range.location]; BOOL viewIsTruncated = NSIntersectionRange(range, truncatedGlyphRange).length != 0;