Skip to content

Commit

Permalink
Fabric: ParagraphShadowNode::updateLocalDataIfNeeded()
Browse files Browse the repository at this point in the history
Summary: Now we don't update `LocalData` for `ParagraphShadowNode` if the attributed string hasn't changed.

Reviewed By: mdvacca

Differential Revision: D13160128

fbshipit-source-id: 6ffe76ad187452fa37ba36a132b885cbcedfd1d3
  • Loading branch information
shergin authored and facebook-github-bot committed Nov 22, 2018
1 parent 7e57755 commit 9c96133
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@ void ParagraphShadowNode::setTextLayoutManager(
textLayoutManager_ = textLayoutManager;
}

void ParagraphShadowNode::updateLocalData() {
void ParagraphShadowNode::updateLocalDataIfNeeded() {
ensureUnsealed();

auto attributedString = getAttributedString();
auto currentLocalData = std::static_pointer_cast<const ParagraphLocalData>(getLocalData());
if (currentLocalData && currentLocalData->getAttributedString() == attributedString) {
return;
}

auto localData = std::make_shared<ParagraphLocalData>();
localData->setAttributedString(getAttributedString());
localData->setAttributedString(std::move(attributedString));
localData->setTextLayoutManager(textLayoutManager_);
setLocalData(localData);
}
Expand All @@ -52,7 +58,7 @@ Size ParagraphShadowNode::measure(LayoutConstraints layoutConstraints) const {
}

void ParagraphShadowNode::layout(LayoutContext layoutContext) {
updateLocalData();
updateLocalDataIfNeeded();
ConcreteViewShadowNode::layout(layoutContext);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ParagraphShadowNode : public ConcreteViewShadowNode<
* Creates a `LocalData` object (with `AttributedText` and
* `TextLayoutManager`) if needed.
*/
void updateLocalData();
void updateLocalDataIfNeeded();

SharedTextLayoutManager textLayoutManager_;

Expand Down

0 comments on commit 9c96133

Please sign in to comment.