diff --git a/ReactCommon/fabric/attributedstring/AttributedString.cpp b/ReactCommon/fabric/attributedstring/AttributedString.cpp index e2b31345016..5a85cb28d7e 100644 --- a/ReactCommon/fabric/attributedstring/AttributedString.cpp +++ b/ReactCommon/fabric/attributedstring/AttributedString.cpp @@ -18,12 +18,12 @@ using Fragments = AttributedString::Fragments; #pragma mark - Fragment bool Fragment::operator==(const Fragment &rhs) const { - return std::tie(string, textAttributes, shadowNode, parentShadowNode) == + return std::tie(string, textAttributes, shadowView, parentShadowView) == std::tie( rhs.string, rhs.textAttributes, - rhs.shadowNode, - rhs.parentShadowNode); + rhs.shadowView, + rhs.parentShadowView); } bool Fragment::operator!=(const Fragment &rhs) const { @@ -90,11 +90,6 @@ SharedDebugStringConvertibleList AttributedString::getDebugChildren() const { auto propsList = fragment.textAttributes.DebugStringConvertible::getDebugProps(); - if (fragment.shadowNode) { - propsList.push_back(std::make_shared( - "shadowNode", fragment.shadowNode->getDebugDescription())); - } - list.push_back(std::make_shared( "Fragment", fragment.string, diff --git a/ReactCommon/fabric/attributedstring/AttributedString.h b/ReactCommon/fabric/attributedstring/AttributedString.h index 2dd66dd7823..e1aa5d83256 100644 --- a/ReactCommon/fabric/attributedstring/AttributedString.h +++ b/ReactCommon/fabric/attributedstring/AttributedString.h @@ -15,6 +15,7 @@ #include #include #include +#include namespace facebook { namespace react { @@ -35,8 +36,8 @@ class AttributedString : public Sealable, public DebugStringConvertible { public: std::string string; TextAttributes textAttributes; - SharedShadowNode shadowNode; - SharedShadowNode parentShadowNode; + ShadowView shadowView; + ShadowView parentShadowView; bool operator==(const Fragment &rhs) const; bool operator!=(const Fragment &rhs) const; @@ -89,7 +90,11 @@ struct hash { size_t operator()( const facebook::react::AttributedString::Fragment &fragment) const { return std::hash{}(fragment.string) + - std::hash{}(fragment.textAttributes); + std::hash{}( + fragment.textAttributes) + + std::hash{}(fragment.shadowView) + + std::hash{}( + fragment.parentShadowView); } }; diff --git a/ReactCommon/fabric/attributedstring/BUCK b/ReactCommon/fabric/attributedstring/BUCK index ba7ffd7ef3e..5fb1286519f 100644 --- a/ReactCommon/fabric/attributedstring/BUCK +++ b/ReactCommon/fabric/attributedstring/BUCK @@ -59,6 +59,7 @@ rn_xplat_cxx_library( react_native_xplat_target("fabric/debug:debug"), react_native_xplat_target("fabric/core:core"), react_native_xplat_target("fabric/graphics:graphics"), + react_native_xplat_target("fabric/mounting:mounting"), ], ) diff --git a/ReactCommon/fabric/attributedstring/conversions.h b/ReactCommon/fabric/attributedstring/conversions.h index fb54e8f4198..4eb49684e57 100644 --- a/ReactCommon/fabric/attributedstring/conversions.h +++ b/ReactCommon/fabric/attributedstring/conversions.h @@ -478,8 +478,8 @@ inline folly::dynamic toDynamic(const AttributedString &attributedString) { for (auto fragment : attributedString.getFragments()) { folly::dynamic dynamicFragment = folly::dynamic::object(); dynamicFragment["string"] = fragment.string; - if (fragment.parentShadowNode) { - dynamicFragment["reactTag"] = fragment.parentShadowNode->getTag(); + if (fragment.parentShadowView.componentHandle) { + dynamicFragment["reactTag"] = fragment.parentShadowView.tag; } dynamicFragment["textAttributes"] = toDynamic(fragment.textAttributes); fragments.push_back(dynamicFragment); diff --git a/ReactCommon/fabric/components/text/basetext/BaseTextShadowNode.cpp b/ReactCommon/fabric/components/text/basetext/BaseTextShadowNode.cpp index aaa8e83e2da..c7443aead7c 100644 --- a/ReactCommon/fabric/components/text/basetext/BaseTextShadowNode.cpp +++ b/ReactCommon/fabric/components/text/basetext/BaseTextShadowNode.cpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace facebook { namespace react { @@ -34,10 +35,7 @@ AttributedString BaseTextShadowNode::getAttributedString( // `attributedString` causes a retain cycle (besides that fact that we // don't need it at all). Storing a `ShadowView` instance instead of // `ShadowNode` should properly fix this problem. - fragment.parentShadowNode = - std::dynamic_pointer_cast(parentNode) - ? parentNode - : nullptr; + fragment.parentShadowView = ShadowView(*parentNode); attributedString.appendFragment(fragment); continue; } @@ -56,7 +54,7 @@ AttributedString BaseTextShadowNode::getAttributedString( // Any other kind of ShadowNode auto fragment = AttributedString::Fragment{}; - fragment.shadowNode = childNode; + fragment.shadowView = 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 0947c9a2f67..09c3ff40d28 100644 --- a/ReactCommon/fabric/textlayoutmanager/platform/ios/RCTAttributedTextUtils.mm +++ b/ReactCommon/fabric/textlayoutmanager/platform/ios/RCTAttributedTextUtils.mm @@ -229,12 +229,9 @@ NSAttributedString *RCTNSAttributedStringFromAttributedString( for (auto fragment : attributedString.getFragments()) { NSAttributedString *nsAttributedStringFragment; - auto layoutableShadowNode = - std::dynamic_pointer_cast( - fragment.shadowNode); + auto layoutMetrics = fragment.shadowView.layoutMetrics; - if (layoutableShadowNode) { - auto layoutMetrics = layoutableShadowNode->getLayoutMetrics(); + if (layoutMetrics != EmptyLayoutMetrics) { CGRect bounds = {.origin = {.x = layoutMetrics.frame.origin.x, .y = layoutMetrics.frame.origin.y}, .size = {.width = layoutMetrics.frame.size.width, @@ -259,11 +256,10 @@ NSAttributedString *RCTNSAttributedStringFromAttributedString( [[NSMutableAttributedString alloc] initWithAttributedString:nsAttributedStringFragment]; - if (fragment.parentShadowNode) { + if (fragment.parentShadowView.componentHandle) { RCTWeakEventEmitterWrapper *eventEmitterWrapper = [RCTWeakEventEmitterWrapper new]; - eventEmitterWrapper.eventEmitter = - fragment.parentShadowNode->getEventEmitter(); + eventEmitterWrapper.eventEmitter = fragment.parentShadowView.eventEmitter; NSDictionary *additionalTextAttributes = @{RCTAttributedStringEventEmitterKey : eventEmitterWrapper};