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: check if its first render before updating from props #419

Merged
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
49 changes: 25 additions & 24 deletions ios/MarkdownCommitHook.mm
Original file line number Diff line number Diff line change
Expand Up @@ -141,30 +141,31 @@
stateData.attributedStringBox);

// Handles the first render, where the text stored in props is
// different than the one stored in state The one in state is empty,
// while the one in props is passed from JS If we don't update the
// state here, we'll end up with a one-default-line-sized text
// input. A better condition to do that can be probably chosen, but
// this seems to work
auto plainString =
std::string([[nsAttributedString string] UTF8String]);
if (plainString != textInputProps.text) {
// creates new AttributedString from props, adapted from
// TextInputShadowNode (ios one, text inputs are
// platform-specific)
auto attributedString = AttributedString{};
attributedString.appendFragment(AttributedString::Fragment{
textInputProps.text, defaultTextAttributes});

auto attachments = BaseTextShadowNode::Attachments{};
BaseTextShadowNode::buildAttributedString(
defaultTextAttributes, *nodes.textInput, attributedString,
attachments);

// convert the newly created attributed string to
// NSAttributedString
nsAttributedString = RCTNSAttributedStringFromAttributedStringBox(
AttributedStringBox{attributedString});
// different than the one stored in state. The one in state is empty,
// while the one in props is passed from JS. If we don't update the
// state here, we'll end up with a one-default-line-sized text input
if (textInputState.getRevision() == State::initialRevisionValue) {
auto plainStringFromState =
std::string([[nsAttributedString string] UTF8String]);

if (plainStringFromState != textInputProps.text) {
// creates new AttributedString from props, adapted from
// TextInputShadowNode (ios one, text inputs are
// platform-specific)
auto attributedString = AttributedString{};
attributedString.appendFragment(AttributedString::Fragment{
textInputProps.text, defaultTextAttributes});

auto attachments = BaseTextShadowNode::Attachments{};
BaseTextShadowNode::buildAttributedString(
defaultTextAttributes, *nodes.textInput, attributedString,
attachments);

// convert the newly created attributed string to
// NSAttributedString
nsAttributedString = RCTNSAttributedStringFromAttributedStringBox(
AttributedStringBox{attributedString});
}
}

// apply markdown
Expand Down
Loading