Skip to content

Commit

Permalink
Mark Text dirty when descendant Text updates occur (#11008)
Browse files Browse the repository at this point in the history
* Mark Text dirty when descendant Text updates occur

Text should be marked dirty when descendant text nodes are added or
removed, and Text should also be marked dirty when descendants of
descendant virtual text nodes have changes to their text content.

This change ensures that the Yoga node for Text is appropriately updated
when these types of changes occur.

Please note, this is likely to create a slight performance regression
for apps that modify nested text content after initial mount, as these
changes previously would not trigger text measurement, and now they
will. But it's worthwhile to trade correctness for a minor performance
benefit.

Resolves #11007

* Change files
  • Loading branch information
rozele committed Dec 14, 2022
1 parent a817f8d commit 06245ff
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Mark Text dirty when descendant Text updates occur",
"packageName": "react-native-windows",
"email": "erozell@outlook.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ void TextPropertyChangedParentVisitor::VisitText(ShadowNodeBase *node) {
}

TextViewManager::UpdateOptimizedText(node);
node->GetViewManager()->MarkDirty(node->m_tag);
}

// Refresh text highlighters
Expand Down
3 changes: 3 additions & 0 deletions vnext/Microsoft.ReactNative/Views/TextViewManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class TextShadowNode final : public ShadowNodeBase {
}

RecalculateTextHighlighters();
GetViewManager()->MarkDirty(m_tag);
}

void removeAllChildren() override {
Expand All @@ -93,6 +94,7 @@ class TextShadowNode final : public ShadowNodeBase {
Super::removeAllChildren();
}
RecalculateTextHighlighters();
GetViewManager()->MarkDirty(m_tag);
}

void RemoveChildAt(int64_t indexToRemove) override {
Expand All @@ -102,6 +104,7 @@ class TextShadowNode final : public ShadowNodeBase {
Super::RemoveChildAt(indexToRemove);
}
RecalculateTextHighlighters();
GetViewManager()->MarkDirty(m_tag);
}

void UpdateOptimizedText() {
Expand Down

0 comments on commit 06245ff

Please sign in to comment.