Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use NSTextStorageDelegate instead of method swizzling #520

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

@tomekzaw
Copy link
Collaborator Author

Regression: Cursor is shifted to the right when adding a newline after a blockquote

Screen.Recording.2024-10-17.at.11.38.34.mov

@tomekzaw
Copy link
Collaborator Author

Bug: spellcheck completely disappears when adding Markdown syntax

Screen.Recording.2024-10-21.at.20.50.18.mov

example/src/App.tsx Outdated Show resolved Hide resolved
apple/RCTMarkdownUtils.mm Outdated Show resolved Hide resolved
apple/MarkdownTextInputDecoratorView.mm Show resolved Hide resolved
apple/MarkdownTextInputDecoratorView.mm Show resolved Hide resolved
apple/MarkdownTextInputDecoratorView.mm Outdated Show resolved Hide resolved
apple/MarkdownTextFieldObserver.h Outdated Show resolved Hide resolved
apple/MarkdownTextFieldObserver.h Outdated Show resolved Hide resolved
apple/MarkdownTextStorageDelegate.h Outdated Show resolved Hide resolved
apple/MarkdownTextInputDecoratorView.mm Outdated Show resolved Hide resolved
@tomekzaw
Copy link
Collaborator Author

tomekzaw commented Nov 5, 2024

Regression: Emojis are not visible

edit: [attributedString addAttributes:defaultTextAttributes range:fullRange]; breaks emoji font

edit2: fixed in 67968ec and explained better in 6e40703

@tomekzaw
Copy link
Collaborator Author

tomekzaw commented Nov 5, 2024

Regression: toggling text color doesn't work (it only works when you toggle markdownStyle first)

edit: it works if text doesn't contain any emojis

edit2: fixed in d377043 and explained better in 6e40703

@tomekzaw tomekzaw force-pushed the @tomekzaw/NSTextStorageDelegate branch from 9a4f995 to 40abeba Compare November 5, 2024 11:57
j-piasecki
j-piasecki previously approved these changes Nov 5, 2024
Copy link
Collaborator

@j-piasecki j-piasecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🪨

@tomekzaw tomekzaw marked this pull request as ready for review November 6, 2024 06:35
Copy link
Collaborator

@j-piasecki j-piasecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🪨 🪨

@tomekzaw
Copy link
Collaborator Author

tomekzaw commented Nov 6, 2024

TODO: confirm that removing NSOriginalFont doesn't break anything (like copying text with emojis from MarkdownTextInput)

/*
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];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants