From 7cf43afa8d6a03ccb4cfdc09f81891eabe8b8b70 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Thu, 12 Dec 2019 11:56:28 -0800 Subject: [PATCH] Fabric: Fixing an incorrect empty image placeholder for NSAttributedString attachment Summary: Same as D18048277 but for Fabric text infra. Changelog: [Internal] Fabric-specific internal change. Reviewed By: PeteTheHeat Differential Revision: D18950415 fbshipit-source-id: 09701e261ecb871b3624260a36dd607fdb70e717 --- .../platform/ios/RCTAttributedTextUtils.mm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ReactCommon/fabric/textlayoutmanager/platform/ios/RCTAttributedTextUtils.mm b/ReactCommon/fabric/textlayoutmanager/platform/ios/RCTAttributedTextUtils.mm index b5ffa1ab382ced..96f92af7afdcd7 100644 --- a/ReactCommon/fabric/textlayoutmanager/platform/ios/RCTAttributedTextUtils.mm +++ b/ReactCommon/fabric/textlayoutmanager/platform/ios/RCTAttributedTextUtils.mm @@ -217,6 +217,12 @@ inline static CGFloat RCTEffectiveFontSizeMultiplierFromTextAttributes(const Tex NSAttributedString *RCTNSAttributedStringFromAttributedString(const AttributedString &attributedString) { + static UIImage *placeholderImage; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + placeholderImage = [[UIImage alloc] init]; + }); + NSMutableAttributedString *nsAttributedString = [[NSMutableAttributedString alloc] init]; [nsAttributedString beginEditing]; @@ -230,6 +236,7 @@ inline static CGFloat RCTEffectiveFontSizeMultiplierFromTextAttributes(const Tex .size = {.width = layoutMetrics.frame.size.width, .height = layoutMetrics.frame.size.height}}; NSTextAttachment *attachment = [NSTextAttachment new]; + attachment.image = placeholderImage; attachment.bounds = bounds; nsAttributedStringFragment = [NSAttributedString attributedStringWithAttachment:attachment];