Skip to content

Commit

Permalink
Fix height update delay on iOS on RN 0.75 with new arch enabled (#474)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomekzaw authored Sep 12, 2024
1 parent 25b47bb commit 4657893
Showing 1 changed file with 47 additions and 0 deletions.
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

0 comments on commit 4657893

Please sign in to comment.