From e04738b7ecec9e7da3aab49bb24a6336b9496b94 Mon Sep 17 00:00:00 2001 From: Eric Rozell Date: Thu, 12 Dec 2024 05:39:51 -0800 Subject: [PATCH] Disable weak event emitter in AttributedString for Mac Catalyst (#48225) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/48225 Fixes https://github.com/facebook/react-native/issues/47762 The weak event emitter in AttributedString attributes is causing a serialization error when typing into a TextInput in a Mac Catalyst build. We can resolve this by not putting the event emitters in the attributed string, but this is likely to cause other issues with event handling for nested components. ## Changelog [iOS][Fixed] - Workaround for Mac Catalyst TextInput crash due to serialization attempt of WeakEventEmitter Reviewed By: NickGerleman Differential Revision: D66664583 fbshipit-source-id: efdfbcb0db4d5e6b9bf7c14f9bbb221faae2d724 --- .../ComponentViews/TextInput/RCTTextInputComponentView.mm | 4 ++++ .../renderer/textlayoutmanager/RCTAttributedTextUtils.mm | 2 ++ 2 files changed, 6 insertions(+) diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm index e67d551c5a8..c595e7af5d1 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm @@ -99,9 +99,11 @@ static NSSet *returnKeyTypesSet; NSMutableDictionary *defaultAttributes = [_backedTextInputView.defaultTextAttributes mutableCopy]; +#if !TARGET_OS_MACCATALYST RCTWeakEventEmitterWrapper *eventEmitterWrapper = [RCTWeakEventEmitterWrapper new]; eventEmitterWrapper.eventEmitter = _eventEmitter; defaultAttributes[RCTAttributedStringEventEmitterKey] = eventEmitterWrapper; +#endif _backedTextInputView.defaultTextAttributes = defaultAttributes; } @@ -262,8 +264,10 @@ static NSSet *returnKeyTypesSet; if (newTextInputProps.textAttributes != oldTextInputProps.textAttributes) { NSMutableDictionary *defaultAttributes = RCTNSTextAttributesFromTextAttributes(newTextInputProps.getEffectiveTextAttributes(RCTFontSizeMultiplier())); +#if !TARGET_OS_MACCATALYST defaultAttributes[RCTAttributedStringEventEmitterKey] = _backedTextInputView.defaultTextAttributes[RCTAttributedStringEventEmitterKey]; +#endif _backedTextInputView.defaultTextAttributes = defaultAttributes; } diff --git a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTAttributedTextUtils.mm b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTAttributedTextUtils.mm index 17eec1f275b..1e551e4b127 100644 --- a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTAttributedTextUtils.mm +++ b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTAttributedTextUtils.mm @@ -403,6 +403,7 @@ static NSMutableAttributedString *RCTNSAttributedStringFragmentWithAttributesFro { auto nsAttributedStringFragment = RCTNSAttributedStringFragmentFromFragment(fragment, placeholderImage); +#if !TARGET_OS_MACCATALYST if (fragment.parentShadowView.componentHandle) { RCTWeakEventEmitterWrapper *eventEmitterWrapper = [RCTWeakEventEmitterWrapper new]; eventEmitterWrapper.eventEmitter = fragment.parentShadowView.eventEmitter; @@ -413,6 +414,7 @@ static NSMutableAttributedString *RCTNSAttributedStringFragmentWithAttributesFro [nsAttributedStringFragment addAttributes:additionalTextAttributes range:NSMakeRange(0, nsAttributedStringFragment.length)]; } +#endif return nsAttributedStringFragment; }