Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tomekzaw committed Nov 5, 2024
1 parent d377043 commit 6e40703
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions apple/RCTMarkdownUtils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,22 @@ - (void)applyFormatting:(nonnull NSMutableAttributedString *)attributedString wi

RCTApplyBaselineOffset(attributedString);

/*
Calling `[attributedString addAttributes:defaultTextAttributes range:fullRange]` breaks the font for emojis.
Before, NSFont attribute is ".SFUI-Regular" and NSOriginalFont attribute is ".AppleColorEmoji".
After the call, both are set to ".SFUI-Regular" which makes emoji invisible and zero-width.
Calling `fixAttributesInRange:` fixes this problem.
*/
[attributedString fixAttributesInRange:fullRange];

/*
When updating MarkdownTextInput's `style` property without changing `markdownStyle`,
React Native calls `[RCTTextInputComponentView _setAttributedString:]` which skips update if strings are equal.
See https://github.com/facebook/react-native/blob/287e20033207df5e59d199a347b7ae2b4cd7a59e/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm#L680-L684
The attributed strings are compared using `[RCTTextInputComponentView _textOf:equals:]` which compares only raw strings
if NSOriginalFont attribute is present. So we purposefully remove this attribute to force update.
See https://github.com/facebook/react-native/blob/287e20033207df5e59d199a347b7ae2b4cd7a59e/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm#L751-L784
*/
[attributedString removeAttribute:@"NSOriginalFont" range:fullRange];

[attributedString endEditing];
Expand Down

0 comments on commit 6e40703

Please sign in to comment.