diff --git a/ReactCommon/fabric/attributedstring/AttributedString.h b/ReactCommon/fabric/attributedstring/AttributedString.h index 560560ceb..49484aff8 100644 --- a/ReactCommon/fabric/attributedstring/AttributedString.h +++ b/ReactCommon/fabric/attributedstring/AttributedString.h @@ -39,6 +39,7 @@ public: std::string string; TextAttributes textAttributes; SharedShadowNode shadowNode; + SharedShadowNode parentShadowNode; }; using Fragments = std::vector; diff --git a/ReactCommon/fabric/components/text/basetext/BaseTextShadowNode.cpp b/ReactCommon/fabric/components/text/basetext/BaseTextShadowNode.cpp index 70904b419..f6832a3d8 100644 --- a/ReactCommon/fabric/components/text/basetext/BaseTextShadowNode.cpp +++ b/ReactCommon/fabric/components/text/basetext/BaseTextShadowNode.cpp @@ -29,6 +29,7 @@ AttributedString BaseTextShadowNode::getAttributedString( AttributedString::Fragment fragment; fragment.string = rawTextShadowNode->getProps()->text; fragment.textAttributes = textAttributes; + fragment.parentShadowNode = parentNode; attributedString.appendFragment(fragment); continue; } diff --git a/ReactCommon/fabric/textlayoutmanager/platform/ios/RCTAttributedTextUtils.h b/ReactCommon/fabric/textlayoutmanager/platform/ios/RCTAttributedTextUtils.h index 32b0a387d..133e1a8ab 100644 --- a/ReactCommon/fabric/textlayoutmanager/platform/ios/RCTAttributedTextUtils.h +++ b/ReactCommon/fabric/textlayoutmanager/platform/ios/RCTAttributedTextUtils.h @@ -13,11 +13,15 @@ NS_ASSUME_NONNULL_BEGIN NSString *const RCTAttributedStringIsHighlightedAttributeName = @"IsHighlighted"; -NSString *const RCTAttributedStringReactTagAttributeName = @"ReactTag"; +NSString *const RCTAttributedStringParentShadowNode = @"ParentShadowNode"; /** * Constructs ready-to-render `NSAttributedString` by given `AttributedString`. */ NSAttributedString *RCTNSAttributedStringFromAttributedString(const facebook::react::AttributedString &attributedString); +@interface RCTSharedShadowNodeWrapper : NSObject +@property (nonatomic, assign) facebook::react::SharedShadowNode node; +@end + NS_ASSUME_NONNULL_END diff --git a/ReactCommon/fabric/textlayoutmanager/platform/ios/RCTAttributedTextUtils.mm b/ReactCommon/fabric/textlayoutmanager/platform/ios/RCTAttributedTextUtils.mm index f0e112188..6c0b3e3a2 100644 --- a/ReactCommon/fabric/textlayoutmanager/platform/ios/RCTAttributedTextUtils.mm +++ b/ReactCommon/fabric/textlayoutmanager/platform/ios/RCTAttributedTextUtils.mm @@ -12,6 +12,9 @@ #include #include +@implementation RCTSharedShadowNodeWrapper +@end + inline static UIFont *RCTEffectiveFontFromTextAttributes(const TextAttributes &textAttributes) { NSString *fontFamily = [NSString stringWithCString:textAttributes.fontFamily.c_str() encoding:NSUTF8StringEncoding]; @@ -209,12 +212,15 @@ NSAttributedString *RCTNSAttributedStringFromAttributedString(const AttributedSt NSMutableAttributedString *nsMutableAttributedStringFragment = [[NSMutableAttributedString alloc] initWithAttributedString:nsAttributedStringFragment]; - if (fragment.shadowNode) { + if (fragment.parentShadowNode) { + RCTSharedShadowNodeWrapper *parentShadowNode = [RCTSharedShadowNodeWrapper new]; + parentShadowNode.node = fragment.parentShadowNode; + NSDictionary *additionalTextAttributes = @{ - RCTAttributedStringReactTagAttributeName: @(fragment.shadowNode->getTag()) + RCTAttributedStringParentShadowNode: parentShadowNode }; - [nsMutableAttributedStringFragment setAttributes:additionalTextAttributes + [nsMutableAttributedStringFragment addAttributes:additionalTextAttributes range:NSMakeRange(0, nsMutableAttributedStringFragment.length)]; }