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

Fix height update delay on iOS on RN 0.75 with new arch enabled #474

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions ios/MarkdownCommitHook.mm
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,53 @@
}
}

// apply markdown
auto newString = [utils parseMarkdown:nsAttributedString
withAttributes:defaultNSTextAttributes];

// create a clone of the old TextInputState and update the
// attributed string box to point to the string with markdown
// applied
auto newStateData = std::make_shared<TextInputState>(stateData);
newStateData->attributedStringBox =
RCTAttributedStringBoxFromNSAttributedString(newString);

// clone the text input with the new state
return node.clone({
.state = std::make_shared<const ConcreteState<TextInputState>>(
newStateData, textInputState),
});
});
} else if (stateData.attributedStringBox.getMode() ==
AttributedStringBox::Mode::OpaquePointer) {
rootNode = rootNode->cloneTree(
nodes.textInput->getFamily(),
[&nodes, &textInputState, &stateData,
fontSizeMultiplier](const ShadowNode &node) {
const auto &markdownProps = *std::static_pointer_cast<
MarkdownTextInputDecoratorViewProps const>(
nodes.decorator->getProps());
const auto &textInputProps =
*std::static_pointer_cast<TextInputProps const>(
nodes.textInput->getProps());

const auto defaultTextAttributes =
textInputProps.getEffectiveTextAttributes(fontSizeMultiplier);
const auto defaultNSTextAttributes =
RCTNSTextAttributesFromTextAttributes(defaultTextAttributes);

// this can possibly be optimized
RCTMarkdownStyle *markdownStyle = [[RCTMarkdownStyle alloc]
initWithStruct:markdownProps.markdownStyle];
RCTMarkdownUtils *utils = [[RCTMarkdownUtils alloc] init];
[utils setMarkdownStyle:markdownStyle];

// convert the attibuted string stored in state to
// NSAttributedString
auto nsAttributedString =
RCTNSAttributedStringFromAttributedStringBox(
stateData.attributedStringBox);

// apply markdown
auto newString = [utils parseMarkdown:nsAttributedString
withAttributes:defaultNSTextAttributes];
Expand Down
Loading