Skip to content

Commit

Permalink
Optimize state updates done in the commit hook (#550)
Browse files Browse the repository at this point in the history
Co-authored-by: Tomek Zawadzki <[email protected]>
  • Loading branch information
j-piasecki and tomekzaw authored Nov 21, 2024
1 parent 6315f7a commit 194e952
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions android/src/main/new_arch/MarkdownCommitHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,26 +107,31 @@ RootShadowNode::Unshared MarkdownCommitHook::shadowTreeWillCommit(
rootNode = rootNode->cloneTree(
nodes.textInput->getFamily(),
[this, &stateData, &textInputState, &nodes](ShadowNode const &node) {
auto newStateData =
std::make_shared<AndroidTextInputState>(stateData);
// force measurement of a map buffer
newStateData->cachedAttributedStringId = 0;

// setting -1 as the event counter makes sure that the update will be ignored by the java
// part of the code, which is what we want as we don't change the attributed string here
if (previousEventCount_.contains(nodes.textInput->getTag()) &&
std::shared_ptr<ShadowNode> newNode = nullptr;

if (stateData.cachedAttributedStringId != 0) {
auto newStateData =
std::make_shared<AndroidTextInputState>(stateData);

// force measurement of a map buffer
newStateData->cachedAttributedStringId = 0;

// setting -1 as the event counter makes sure that the update will be ignored by the java
// part of the code, which is what we want as we don't change the attributed string here
if (previousEventCount_.contains(nodes.textInput->getTag()) &&
previousEventCount_[nodes.textInput->getTag()] == stateData.mostRecentEventCount) {
newStateData->mostRecentEventCount = -1;
} else {
} else {
previousEventCount_[nodes.textInput->getTag()] = stateData.mostRecentEventCount;
}
}

auto newState = std::make_shared<const ConcreteState<AndroidTextInputState>>(
newStateData, textInputState);

// clone the text input with the new state
auto newNode = node.clone({
.state =
std::make_shared<const ConcreteState<AndroidTextInputState>>(
newStateData, textInputState),
});
newNode = node.clone({ .state = newState });
} else {
newNode = node.clone({});
}

const auto currentDecoratorProps =
nodes.decorator->getProps()->rawProps["markdownStyle"];
Expand Down

0 comments on commit 194e952

Please sign in to comment.