Skip to content

Commit

Permalink
Fix selection getting lost on Android on the new arch (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
j-piasecki authored Apr 26, 2024
1 parent 306d6f5 commit 5404e93
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions android/src/main/new_arch/MarkdownCommitHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ RootShadowNode::Unshared MarkdownCommitHook::shadowTreeWillCommit(
// 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 {
previousEventCount_[nodes.textInput->getTag()] = stateData.mostRecentEventCount;
}

// clone the text input with the new state
auto newNode = node.clone({
.state =
Expand Down
2 changes: 2 additions & 0 deletions android/src/main/new_arch/MarkdownCommitHook.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class MarkdownCommitHook : public UIManagerCommitHook {
textLayoutManagers_;
std::unordered_map<facebook::react::Tag, folly::dynamic>
previousDecoratorProps_;
std::unordered_map<facebook::react::Tag, int64_t>
previousEventCount_;
};

} // namespace livemarkdown

0 comments on commit 5404e93

Please sign in to comment.