Skip to content

Commit 4ae9ec1

Browse files
sherginfacebook-github-bot
authored andcommitted
Fabric: RootShadowNode::layoutIfNeeded
Summary: Reasons: * The name of the method now better represent what it's doing; * It exposes information about "dirty" state of the node without opening actual `LayoutableShadowNode` protected APIs; * It's a tiny bit faster now because it checks the flag before calling Yoga. Changelog: [Internal] Fabric-specific internal change. Reviewed By: sammy-SC Differential Revision: D19596282 fbshipit-source-id: 3d87d9d5ba20bb8e360683f149b5ebf90beecd65
1 parent 055a41b commit 4ae9ec1

File tree

5 files changed

+15
-9
lines changed

5 files changed

+15
-9
lines changed

ReactCommon/fabric/components/root/RootShadowNode.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@ namespace react {
1515

1616
const char RootComponentName[] = "RootView";
1717

18-
void RootShadowNode::layout(
18+
bool RootShadowNode::layoutIfNeeded(
1919
std::vector<LayoutableShadowNode const *> *affectedNodes) {
2020
SystraceSection s("RootShadowNode::layout");
21+
22+
if (getIsLayoutClean()) {
23+
return false;
24+
}
25+
2126
ensureUnsealed();
2227

2328
auto layoutContext = getProps()->layoutContext;
@@ -31,6 +36,8 @@ void RootShadowNode::layout(
3136
setLayoutMetrics(layoutMetricsFromYogaNode(yogaNode_));
3237
setHasNewLayout(false);
3338
}
39+
40+
return true;
3441
}
3542

3643
RootShadowNode::Unshared RootShadowNode::clone(

ReactCommon/fabric/components/root/RootShadowNode.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ class RootShadowNode final
3535
using Unshared = std::shared_ptr<RootShadowNode>;
3636

3737
/*
38-
* Layouts the shadow tree.
38+
* Layouts the shadow tree if needed.
39+
* Returns `false` if the three is already laid out.
3940
*/
40-
void layout(std::vector<LayoutableShadowNode const *> *affectedNodes = {});
41+
bool layoutIfNeeded(
42+
std::vector<LayoutableShadowNode const *> *affectedNodes = {});
4143

4244
/*
4345
* Clones the node with given `layoutConstraints` and `layoutContext`.
@@ -58,9 +60,6 @@ class RootShadowNode final
5860
ShadowNodeFamily const &shadowNodeFamily,
5961
std::function<ShadowNode::Unshared(ShadowNode const &oldShadowNode)>
6062
callback) const;
61-
62-
private:
63-
using YogaLayoutableShadowNode::layout;
6463
};
6564

6665
} // namespace react

ReactCommon/fabric/mounting/ShadowTree.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ bool ShadowTree::tryCommit(ShadowTreeCommitTransaction transaction) const {
169169
affectedLayoutableNodes.reserve(1024);
170170

171171
telemetry.willLayout();
172-
newRootShadowNode->layout(&affectedLayoutableNodes);
172+
newRootShadowNode->layoutIfNeeded(&affectedLayoutableNodes);
173173
telemetry.didLayout();
174174

175175
newRootShadowNode->sealRecursive();

ReactCommon/fabric/mounting/tests/ShadowTreeLifeCycleTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static void testShadowNodeTreeLifeCycle(
9292

9393
// Laying out the tree.
9494
std::const_pointer_cast<RootShadowNode>(nextRootNode)
95-
->layout(&affectedLayoutableNodes);
95+
->layoutIfNeeded(&affectedLayoutableNodes);
9696

9797
nextRootNode->sealRecursive();
9898
allNodes.push_back(nextRootNode);

ReactCommon/fabric/uimanager/Scheduler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ Size Scheduler::measureSurface(
234234
[&](RootShadowNode::Shared const &oldRootShadowNode) {
235235
auto rootShadowNode =
236236
oldRootShadowNode->clone(layoutConstraints, layoutContext);
237-
rootShadowNode->layout();
237+
rootShadowNode->layoutIfNeeded();
238238
size = rootShadowNode->getLayoutMetrics().frame.size;
239239
return nullptr;
240240
});

0 commit comments

Comments
 (0)