Skip to content

Commit e04738b

Browse files
rozelefacebook-github-bot
authored andcommitted
Disable weak event emitter in AttributedString for Mac Catalyst (#48225)
Summary: Pull Request resolved: #48225 Fixes #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 <Text> 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
1 parent 9888b49 commit e04738b

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,11 @@ - (void)updateEventEmitter:(const EventEmitter::Shared &)eventEmitter
9999
NSMutableDictionary<NSAttributedStringKey, id> *defaultAttributes =
100100
[_backedTextInputView.defaultTextAttributes mutableCopy];
101101

102+
#if !TARGET_OS_MACCATALYST
102103
RCTWeakEventEmitterWrapper *eventEmitterWrapper = [RCTWeakEventEmitterWrapper new];
103104
eventEmitterWrapper.eventEmitter = _eventEmitter;
104105
defaultAttributes[RCTAttributedStringEventEmitterKey] = eventEmitterWrapper;
106+
#endif
105107

106108
_backedTextInputView.defaultTextAttributes = defaultAttributes;
107109
}
@@ -262,8 +264,10 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
262264
if (newTextInputProps.textAttributes != oldTextInputProps.textAttributes) {
263265
NSMutableDictionary<NSAttributedStringKey, id> *defaultAttributes =
264266
RCTNSTextAttributesFromTextAttributes(newTextInputProps.getEffectiveTextAttributes(RCTFontSizeMultiplier()));
267+
#if !TARGET_OS_MACCATALYST
265268
defaultAttributes[RCTAttributedStringEventEmitterKey] =
266269
_backedTextInputView.defaultTextAttributes[RCTAttributedStringEventEmitterKey];
270+
#endif
267271
_backedTextInputView.defaultTextAttributes = defaultAttributes;
268272
}
269273

packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTAttributedTextUtils.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ void RCTApplyBaselineOffset(NSMutableAttributedString *attributedText)
403403
{
404404
auto nsAttributedStringFragment = RCTNSAttributedStringFragmentFromFragment(fragment, placeholderImage);
405405

406+
#if !TARGET_OS_MACCATALYST
406407
if (fragment.parentShadowView.componentHandle) {
407408
RCTWeakEventEmitterWrapper *eventEmitterWrapper = [RCTWeakEventEmitterWrapper new];
408409
eventEmitterWrapper.eventEmitter = fragment.parentShadowView.eventEmitter;
@@ -413,6 +414,7 @@ void RCTApplyBaselineOffset(NSMutableAttributedString *attributedText)
413414
[nsAttributedStringFragment addAttributes:additionalTextAttributes
414415
range:NSMakeRange(0, nsAttributedStringFragment.length)];
415416
}
417+
#endif
416418

417419
return nsAttributedStringFragment;
418420
}

0 commit comments

Comments
 (0)