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

Replace the commit hook with a wrapper component based on display: contents #566

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

Conversation

j-piasecki
Copy link
Collaborator

@j-piasecki j-piasecki commented Dec 6, 2024

Details

React Native 0.77 comes with support for display: contents which would allow to make a wrapper component that doesn't impact layout in any way. This can be used to replace the commit hook to apply markdown styles without cloning the tree.

Related Issues

GH_LINK

Manual Tests

Linked PRs

Comment on lines 78 to 79
const auto &mutableChild =
std::const_pointer_cast<TextInputShadowNode>(child);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The logic here (not specifically these lines, in general) assumes that if the decorator node is mutable, the child text input is also mutable. I'm not actually sure whether this assumption always holds true.

It may make sense to check the children in the constructor and clone them if fragment.children is null and the children list is not empty to ensure the child is mutable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This should be fine? Rerendering the decorator node should also rerender the text input underneath.

@j-piasecki j-piasecki force-pushed the @jpiasecki/display-contents branch from 0edb26e to 26f8433 Compare March 4, 2025 20:52
@j-piasecki j-piasecki marked this pull request as ready for review March 6, 2025 19:11
@j-piasecki j-piasecki requested a review from tomekzaw March 6, 2025 19:11
@tomekzaw tomekzaw linked an issue Mar 11, 2025 that may be closed by this pull request
Comment on lines +68 to +76
const auto &children = getChildren();
react_native_assert(
children.size() == 1 &&
"MarkdownTextInputDecoratorView received wrong number of children");

const auto child =
std::static_pointer_cast<const TextInputShadowNode>(children.at(0));

child->ensureUnsealed();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's move this common logic to a utility function called something like getMutableTextInputShadowNodeFromChildren but in a separate PR

// apply markdown formatting before measuring the child
const auto &mutableChild =
std::const_pointer_cast<TextInputShadowNode>(child);
applyMarkdown(mutableChild, layoutContext);
Copy link
Collaborator

Choose a reason for hiding this comment

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

TODO: rename applyMarkdown so it explicitly says what it does under the hood

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is applyMarkdownStylesToTextInputState ok?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Comment on lines +135 to +140
// this can possibly be optimized
RCTMarkdownStyle *markdownStyle =
[[RCTMarkdownStyle alloc] initWithStruct:markdownProps.markdownStyle];
RCTMarkdownUtils *utils = [[RCTMarkdownUtils alloc] init];
[utils setMarkdownStyle:markdownStyle];
[utils setParserId:[NSNumber numberWithInt:markdownProps.parserId]];
Copy link
Collaborator

Choose a reason for hiding this comment

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

TODO: store this somewhere pretty please in a separate PR

j-piasecki and others added 7 commits March 12, 2025 19:26
Co-authored-by: Tomek Zawadzki <tomekzawadzki98@gmail.com>
…downSpec/MarkdownTextInputDecoratorShadowNode.cpp

Co-authored-by: Tomek Zawadzki <tomekzawadzki98@gmail.com>
…downSpec/MarkdownTextInputDecoratorShadowNode.cpp

Co-authored-by: Tomek Zawadzki <tomekzawadzki98@gmail.com>
Co-authored-by: Tomek Zawadzki <tomekzawadzki98@gmail.com>
…downSpec/MarkdownTextInputDecoratorShadowNode.cpp

Co-authored-by: Tomek Zawadzki <tomekzawadzki98@gmail.com>
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.

SafeAreaView not respected when MarkdownTextInput rendered
2 participants