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
This commit is contained in:
Valentin Shergin 2020-01-31 21:35:41 -08:00 коммит произвёл Facebook Github Bot
Родитель 055a41b081
Коммит 4ae9ec128d
5 изменённых файлов: 15 добавлений и 9 удалений

Просмотреть файл

@ -15,9 +15,14 @@ namespace react {
const char RootComponentName[] = "RootView";
void RootShadowNode::layout(
bool RootShadowNode::layoutIfNeeded(
std::vector<LayoutableShadowNode const *> *affectedNodes) {
SystraceSection s("RootShadowNode::layout");
if (getIsLayoutClean()) {
return false;
}
ensureUnsealed();
auto layoutContext = getProps()->layoutContext;
@ -31,6 +36,8 @@ void RootShadowNode::layout(
setLayoutMetrics(layoutMetricsFromYogaNode(yogaNode_));
setHasNewLayout(false);
}
return true;
}
RootShadowNode::Unshared RootShadowNode::clone(

Просмотреть файл

@ -35,9 +35,11 @@ class RootShadowNode final
using Unshared = std::shared_ptr<RootShadowNode>;
/*
* Layouts the shadow tree.
* Layouts the shadow tree if needed.
* Returns `false` if the three is already laid out.
*/
void layout(std::vector<LayoutableShadowNode const *> *affectedNodes = {});
bool layoutIfNeeded(
std::vector<LayoutableShadowNode const *> *affectedNodes = {});
/*
* Clones the node with given `layoutConstraints` and `layoutContext`.
@ -58,9 +60,6 @@ class RootShadowNode final
ShadowNodeFamily const &shadowNodeFamily,
std::function<ShadowNode::Unshared(ShadowNode const &oldShadowNode)>
callback) const;
private:
using YogaLayoutableShadowNode::layout;
};
} // namespace react

Просмотреть файл

@ -169,7 +169,7 @@ bool ShadowTree::tryCommit(ShadowTreeCommitTransaction transaction) const {
affectedLayoutableNodes.reserve(1024);
telemetry.willLayout();
newRootShadowNode->layout(&affectedLayoutableNodes);
newRootShadowNode->layoutIfNeeded(&affectedLayoutableNodes);
telemetry.didLayout();
newRootShadowNode->sealRecursive();

Просмотреть файл

@ -92,7 +92,7 @@ static void testShadowNodeTreeLifeCycle(
// Laying out the tree.
std::const_pointer_cast<RootShadowNode>(nextRootNode)
->layout(&affectedLayoutableNodes);
->layoutIfNeeded(&affectedLayoutableNodes);
nextRootNode->sealRecursive();
allNodes.push_back(nextRootNode);

Просмотреть файл

@ -234,7 +234,7 @@ Size Scheduler::measureSurface(
[&](RootShadowNode::Shared const &oldRootShadowNode) {
auto rootShadowNode =
oldRootShadowNode->clone(layoutConstraints, layoutContext);
rootShadowNode->layout();
rootShadowNode->layoutIfNeeded();
size = rootShadowNode->getLayoutMetrics().frame.size;
return nullptr;
});