diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/BaseTextInputShadowNode.h b/packages/react-native/ReactCommon/react/renderer/components/textinput/BaseTextInputShadowNode.h index 984db279df53..0365ea8f97e1 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/BaseTextInputShadowNode.h +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/BaseTextInputShadowNode.h @@ -25,6 +25,15 @@ namespace facebook::react { +inline ShadowView shadowViewFromShadowNode(const ShadowNode& shadowNode) { + auto shadowView = ShadowView{shadowNode}; + // Clearing `props` and `state` (which we don't use) allows avoiding retain + // cycles. + shadowView.props = nullptr; + shadowView.state = nullptr; + return shadowView; +} + /* * Base `ShadowNode` for component. */ @@ -171,7 +180,7 @@ class BaseTextInputShadowNode AttributedString attributedString; attributedString.appendFragment( AttributedString::Fragment{ - .string = props.text, .textAttributes = textAttributes, .parentShadowView = ShadowView(*this)}); + .string = props.text, .textAttributes = textAttributes, .parentShadowView = shadowViewFromShadowNode(*this)}); auto attachments = BaseTextShadowNode::Attachments{}; BaseTextShadowNode::buildAttributedString(textAttributes, *this, attributedString, attachments);