Fabric: Fixed issue where root shadow node does not layout itself

Summary: Conceptually, it always must be node owner's responsibility, but for the root node, we have to make an exception because there is no another parent node and there is no another component which has access to YogaNode.

Reviewed By: fkgozali

Differential Revision: D7958251

fbshipit-source-id: 0bdaea87adbd323c758bc3c28f325be615aa90f3
This commit is contained in:
Valentin Shergin 2018-05-15 23:32:33 -07:00 committed by Facebook Github Bot
parent 274c1757e6
commit 10c5368c37
2 changed files with 8 additions and 1 deletions

View File

@ -6,6 +6,7 @@
*/
#include "RootShadowNode.h"
#include "conversions.h"
namespace facebook {
namespace react {
@ -17,6 +18,11 @@ ComponentName RootShadowNode::getComponentName() const {
void RootShadowNode::layout() {
ensureUnsealed();
layout(getProps()->layoutContext);
// This is the rare place where shadow node must layout (set `layoutMetrics`)
// itself because there is no a parent node which usually should do it.
YGNode *yogaNode = const_cast<YGNode *>(yogaNode_.get());
setLayoutMetrics(layoutMetricsFromYogaNode(*yogaNode));
}
} // namespace react

View File

@ -82,9 +82,10 @@ public:
void layoutChildren(LayoutContext layoutContext) override;
private:
protected:
mutable SharedYogaNode yogaNode_;
private:
static SharedYogaConfig suitableYogaConfig();
static void setYogaNodeChildrenBasedOnShadowNodeChildren(YGNode &yogaNode, const SharedShadowNodeSharedList &children);
static YGNode *yogaNodeCloneCallbackConnector(YGNode *oldYogaNode, YGNode *parentYogaNode, int childIndex);