Skip to content

Commit

Permalink
Disable weak event emitter in AttributedString for Mac Catalyst (#48225)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rozele authored and facebook-github-bot committed Dec 12, 2024
1 parent 9888b49 commit e04738b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,11 @@ - (void)updateEventEmitter:(const EventEmitter::Shared &)eventEmitter
NSMutableDictionary<NSAttributedStringKey, id> *defaultAttributes =
[_backedTextInputView.defaultTextAttributes mutableCopy];

#if !TARGET_OS_MACCATALYST
RCTWeakEventEmitterWrapper *eventEmitterWrapper = [RCTWeakEventEmitterWrapper new];
eventEmitterWrapper.eventEmitter = _eventEmitter;
defaultAttributes[RCTAttributedStringEventEmitterKey] = eventEmitterWrapper;
#endif

_backedTextInputView.defaultTextAttributes = defaultAttributes;
}
Expand Down Expand Up @@ -262,8 +264,10 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
if (newTextInputProps.textAttributes != oldTextInputProps.textAttributes) {
NSMutableDictionary<NSAttributedStringKey, id> *defaultAttributes =
RCTNSTextAttributesFromTextAttributes(newTextInputProps.getEffectiveTextAttributes(RCTFontSizeMultiplier()));
#if !TARGET_OS_MACCATALYST
defaultAttributes[RCTAttributedStringEventEmitterKey] =
_backedTextInputView.defaultTextAttributes[RCTAttributedStringEventEmitterKey];
#endif
_backedTextInputView.defaultTextAttributes = defaultAttributes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ void RCTApplyBaselineOffset(NSMutableAttributedString *attributedText)
{
auto nsAttributedStringFragment = RCTNSAttributedStringFragmentFromFragment(fragment, placeholderImage);

#if !TARGET_OS_MACCATALYST
if (fragment.parentShadowView.componentHandle) {
RCTWeakEventEmitterWrapper *eventEmitterWrapper = [RCTWeakEventEmitterWrapper new];
eventEmitterWrapper.eventEmitter = fragment.parentShadowView.eventEmitter;
Expand All @@ -413,6 +414,7 @@ void RCTApplyBaselineOffset(NSMutableAttributedString *attributedText)
[nsAttributedStringFragment addAttributes:additionalTextAttributes
range:NSMakeRange(0, nsAttributedStringFragment.length)];
}
#endif

return nsAttributedStringFragment;
}
Expand Down

0 comments on commit e04738b

Please sign in to comment.