diff --git a/ReactCommon/fabric/attributedstring/AttributedString.cpp b/ReactCommon/fabric/attributedstring/AttributedString.cpp index 1902c7a9af3..974d214ea69 100644 --- a/ReactCommon/fabric/attributedstring/AttributedString.cpp +++ b/ReactCommon/fabric/attributedstring/AttributedString.cpp @@ -17,13 +17,17 @@ using Fragments = AttributedString::Fragments; #pragma mark - Fragment +std::string Fragment::AttachmentCharacter() { + return "\uFFFC"; // Unicode `OBJECT REPLACEMENT CHARACTER` +} + +bool Fragment::isAttachment() const { + return string == AttachmentCharacter(); +} + bool Fragment::operator==(const Fragment &rhs) const { - return std::tie(string, textAttributes, shadowView, parentShadowView) == - std::tie( - rhs.string, - rhs.textAttributes, - rhs.shadowView, - rhs.parentShadowView); + return std::tie(string, textAttributes, parentShadowView) == + std::tie(rhs.string, rhs.textAttributes, rhs.parentShadowView); } bool Fragment::operator!=(const Fragment &rhs) const { diff --git a/ReactCommon/fabric/attributedstring/AttributedString.h b/ReactCommon/fabric/attributedstring/AttributedString.h index 08e4bd11567..7a952e4bfcf 100644 --- a/ReactCommon/fabric/attributedstring/AttributedString.h +++ b/ReactCommon/fabric/attributedstring/AttributedString.h @@ -35,11 +35,18 @@ class AttributedString : public Sealable, public DebugStringConvertible { public: class Fragment { public: + static std::string AttachmentCharacter(); + std::string string; TextAttributes textAttributes; - ShadowView shadowView; ShadowView parentShadowView; + /* + * Returns true is the Fragment represents an attachment. + * Equivalent to `string == AttachmentCharacter()`. + */ + bool isAttachment() const; + bool operator==(const Fragment &rhs) const; bool operator!=(const Fragment &rhs) const; }; @@ -99,7 +106,6 @@ struct hash { 0, fragment.string, fragment.textAttributes, - fragment.shadowView, fragment.parentShadowView); } }; diff --git a/ReactCommon/fabric/components/text/basetext/BaseTextShadowNode.cpp b/ReactCommon/fabric/components/text/basetext/BaseTextShadowNode.cpp index 927445be33e..d873d6025a6 100644 --- a/ReactCommon/fabric/components/text/basetext/BaseTextShadowNode.cpp +++ b/ReactCommon/fabric/components/text/basetext/BaseTextShadowNode.cpp @@ -54,7 +54,8 @@ AttributedString BaseTextShadowNode::getAttributedString( // Any other kind of ShadowNode auto fragment = AttributedString::Fragment{}; - fragment.shadowView = ShadowView(*childNode); + fragment.string = AttributedString::Fragment::AttachmentCharacter(); + fragment.parentShadowView = ShadowView(*childNode); fragment.textAttributes = textAttributes; attributedString.appendFragment(fragment); } diff --git a/ReactCommon/fabric/textlayoutmanager/platform/ios/RCTAttributedTextUtils.mm b/ReactCommon/fabric/textlayoutmanager/platform/ios/RCTAttributedTextUtils.mm index 73b1c0e5133..b5ffa1ab382 100644 --- a/ReactCommon/fabric/textlayoutmanager/platform/ios/RCTAttributedTextUtils.mm +++ b/ReactCommon/fabric/textlayoutmanager/platform/ios/RCTAttributedTextUtils.mm @@ -224,9 +224,8 @@ NSAttributedString *RCTNSAttributedStringFromAttributedString(const AttributedSt for (auto fragment : attributedString.getFragments()) { NSAttributedString *nsAttributedStringFragment; - auto layoutMetrics = fragment.shadowView.layoutMetrics; - - if (layoutMetrics != EmptyLayoutMetrics) { + if (fragment.isAttachment()) { + auto layoutMetrics = fragment.parentShadowView.layoutMetrics; CGRect bounds = {.origin = {.x = layoutMetrics.frame.origin.x, .y = layoutMetrics.frame.origin.y}, .size = {.width = layoutMetrics.frame.size.width, .height = layoutMetrics.frame.size.height}};