Fabric: Introducing `RootShadowNode`

Summary: `RootShadowNode` is a dedicated class for managing the root node.

Reviewed By: mdvacca

Differential Revision: D7857050

fbshipit-source-id: f15f4b177f03cea4c0fd5a60d761ee2745319d77
This commit is contained in:
Valentin Shergin 2018-05-08 22:56:14 -07:00 committed by Facebook Github Bot
parent cb48fa4d49
commit 2bb41031ba
7 changed files with 164 additions and 7 deletions

View File

@ -81,7 +81,6 @@ public:
const SharedConcreteProps getProps() const {
assert(std::dynamic_pointer_cast<const PropsT>(props_));
return std::static_pointer_cast<const PropsT>(props_);
}

View File

@ -9,16 +9,11 @@
#include <fabric/uimanager/SchedulerDelegate.h>
#include <fabric/uimanager/UIManagerDelegate.h>
#include <fabric/view/ViewShadowNode.h>
#include <fabric/view/RootShadowNode.h>
namespace facebook {
namespace react {
/*
* We expect having a dedicated subclass for root shadow node.
*/
using SharedRootShadowNode = SharedViewShadowNode;
using RootShadowNode = ViewShadowNode;
class FabricUIManager;
/*

View File

@ -22,6 +22,7 @@ rn_xplat_cxx_library(
[
("", "*.h"),
("accessibility", "*.h"),
("root", "*.h"),
("yoga", "*.h"),
],
prefix = "fabric/view",

View File

@ -0,0 +1,45 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "RootProps.h"
#include "yogaValuesConversions.h"
namespace facebook {
namespace react {
void RootProps::applyLayoutConstraints(const LayoutConstraints &layoutConstraints) {
ensureUnsealed();
layoutConstraints_ = layoutConstraints;
yogaStyle_.minDimensions[YGDimensionWidth] =
yogaStyleValueFromFloat(layoutConstraints.minimumSize.width);
yogaStyle_.minDimensions[YGDimensionHeight] =
yogaStyleValueFromFloat(layoutConstraints.minimumSize.height);
yogaStyle_.maxDimensions[YGDimensionWidth] =
yogaStyleValueFromFloat(layoutConstraints.maximumSize.width);
yogaStyle_.maxDimensions[YGDimensionHeight] =
yogaStyleValueFromFloat(layoutConstraints.maximumSize.height);
}
void RootProps::applyLayoutContext(const LayoutContext &layoutContext) {
ensureUnsealed();
layoutContext_ = layoutContext;
}
LayoutConstraints RootProps::getLayoutConstraints() const {
return layoutConstraints_;
}
LayoutContext RootProps::getLayoutContext() const {
return layoutContext_;
}
} // namespace react
} // namespace facebook

View File

@ -0,0 +1,44 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <memory>
#include <fabric/core/LayoutConstraints.h>
#include <fabric/core/LayoutContext.h>
#include <fabric/view/ViewProps.h>
namespace facebook {
namespace react {
class RootProps;
using SharedRootProps = std::shared_ptr<const RootProps>;
class RootProps final:
public ViewProps {
public:
/*
* Same semantic as `apply()` but LayoutConstraints & LayoutContext specific.
*/
void applyLayoutConstraints(const LayoutConstraints &layoutConstraints);
void applyLayoutContext(const LayoutContext &layoutContext);
LayoutConstraints getLayoutConstraints() const;
LayoutContext getLayoutContext() const;
private:
LayoutConstraints layoutConstraints_;
LayoutContext layoutContext_;
};
} // namespace react
} // namespace facebook

View File

@ -0,0 +1,23 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "RootShadowNode.h"
namespace facebook {
namespace react {
ComponentName RootShadowNode::getComponentName() const {
return ComponentName("RootView");
}
void RootShadowNode::layout() {
ensureUnsealed();
layout(getProps()->getLayoutContext());
}
} // namespace react
} // namespace facebook

View File

@ -0,0 +1,50 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <memory>
#include <fabric/core/LayoutContext.h>
#include <fabric/view/RootProps.h>
#include <fabric/view/ConcreteViewShadowNode.h>
namespace facebook {
namespace react {
class RootShadowNode;
using SharedRootShadowNode = std::shared_ptr<const RootShadowNode>;
using UnsharedRootShadowNode = std::shared_ptr<RootShadowNode>;
/*
* `ShadowNode` for the root component.
* Besides all functionality of the `View` component, `RootShadowNode` contains
* props which represent external layout constraints and context of the
* shadow tree.
*/
class RootShadowNode final:
public ConcreteViewShadowNode<RootProps> {
public:
using ConcreteViewShadowNode::ConcreteViewShadowNode;
ComponentName getComponentName() const override;
/*
* Layouts the shadow tree.
*/
void layout();
private:
using YogaLayoutableShadowNode::layout;
};
} // namespace react
} // namespace facebook