diff --git a/ReactCommon/fabric/core/shadownode/ConcreteShadowNode.h b/ReactCommon/fabric/core/shadownode/ConcreteShadowNode.h index aca5fc32b..06a1afa7c 100644 --- a/ReactCommon/fabric/core/shadownode/ConcreteShadowNode.h +++ b/ReactCommon/fabric/core/shadownode/ConcreteShadowNode.h @@ -81,7 +81,6 @@ public: const SharedConcreteProps getProps() const { assert(std::dynamic_pointer_cast(props_)); - return std::static_pointer_cast(props_); } diff --git a/ReactCommon/fabric/uimanager/Scheduler.h b/ReactCommon/fabric/uimanager/Scheduler.h index b48d6e848..5082f9bb6 100644 --- a/ReactCommon/fabric/uimanager/Scheduler.h +++ b/ReactCommon/fabric/uimanager/Scheduler.h @@ -9,16 +9,11 @@ #include #include #include +#include namespace facebook { namespace react { -/* - * We expect having a dedicated subclass for root shadow node. - */ -using SharedRootShadowNode = SharedViewShadowNode; -using RootShadowNode = ViewShadowNode; - class FabricUIManager; /* diff --git a/ReactCommon/fabric/view/BUCK b/ReactCommon/fabric/view/BUCK index 221ea2c10..5665baed3 100644 --- a/ReactCommon/fabric/view/BUCK +++ b/ReactCommon/fabric/view/BUCK @@ -22,6 +22,7 @@ rn_xplat_cxx_library( [ ("", "*.h"), ("accessibility", "*.h"), + ("root", "*.h"), ("yoga", "*.h"), ], prefix = "fabric/view", diff --git a/ReactCommon/fabric/view/root/RootProps.cpp b/ReactCommon/fabric/view/root/RootProps.cpp new file mode 100644 index 000000000..e8f0beced --- /dev/null +++ b/ReactCommon/fabric/view/root/RootProps.cpp @@ -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 diff --git a/ReactCommon/fabric/view/root/RootProps.h b/ReactCommon/fabric/view/root/RootProps.h new file mode 100644 index 000000000..f8c40f361 --- /dev/null +++ b/ReactCommon/fabric/view/root/RootProps.h @@ -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 + +#include +#include +#include + +namespace facebook { +namespace react { + +class RootProps; + +using SharedRootProps = std::shared_ptr; + +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 diff --git a/ReactCommon/fabric/view/root/RootShadowNode.cpp b/ReactCommon/fabric/view/root/RootShadowNode.cpp new file mode 100644 index 000000000..97dc7dd01 --- /dev/null +++ b/ReactCommon/fabric/view/root/RootShadowNode.cpp @@ -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 diff --git a/ReactCommon/fabric/view/root/RootShadowNode.h b/ReactCommon/fabric/view/root/RootShadowNode.h new file mode 100644 index 000000000..6508fa587 --- /dev/null +++ b/ReactCommon/fabric/view/root/RootShadowNode.h @@ -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 + +#include +#include +#include + +namespace facebook { +namespace react { + +class RootShadowNode; + +using SharedRootShadowNode = std::shared_ptr; +using UnsharedRootShadowNode = std::shared_ptr; + +/* + * `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 { + +public: + + using ConcreteViewShadowNode::ConcreteViewShadowNode; + + ComponentName getComponentName() const override; + + /* + * Layouts the shadow tree. + */ + void layout(); + +private: + + using YogaLayoutableShadowNode::layout; +}; + +} // namespace react +} // namespace facebook