2018-03-19 02:04:20 +00:00
|
|
|
/**
|
|
|
|
* 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 "LayoutableShadowNode.h"
|
|
|
|
|
|
|
|
#include <fabric/core/LayoutConstraints.h>
|
|
|
|
#include <fabric/core/LayoutContext.h>
|
|
|
|
#include <fabric/core/LayoutMetrics.h>
|
2018-04-27 00:51:35 +00:00
|
|
|
#include <fabric/debug/DebugStringConvertibleItem.h>
|
2018-05-14 22:43:48 +00:00
|
|
|
#include <fabric/graphics/conversions.h>
|
2018-03-19 02:04:20 +00:00
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace react {
|
|
|
|
|
|
|
|
LayoutMetrics LayoutableShadowNode::getLayoutMetrics() const {
|
|
|
|
return layoutMetrics_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LayoutableShadowNode::setLayoutMetrics(LayoutMetrics layoutMetrics) {
|
2018-03-19 23:51:30 +00:00
|
|
|
if (layoutMetrics_ == layoutMetrics) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-10 19:45:35 +00:00
|
|
|
ensureUnsealed();
|
|
|
|
|
2018-03-19 02:04:20 +00:00
|
|
|
layoutMetrics_ = layoutMetrics;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayoutableShadowNode::cleanLayout() {
|
|
|
|
isLayoutClean_ = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayoutableShadowNode::dirtyLayout() {
|
|
|
|
isLayoutClean_ = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LayoutableShadowNode::getIsLayoutClean() const {
|
|
|
|
return isLayoutClean_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LayoutableShadowNode::getHasNewLayout() const {
|
|
|
|
return hasNewLayout_;
|
|
|
|
};
|
|
|
|
|
|
|
|
void LayoutableShadowNode::setHasNewLayout(bool hasNewLayout) {
|
|
|
|
hasNewLayout_ = hasNewLayout;
|
|
|
|
}
|
|
|
|
|
|
|
|
Size LayoutableShadowNode::measure(LayoutConstraints layoutConstraints) const {
|
|
|
|
return Size();
|
|
|
|
}
|
|
|
|
|
|
|
|
Float LayoutableShadowNode::firstBaseline(Size size) const {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Float LayoutableShadowNode::lastBaseline(Size size) const {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayoutableShadowNode::layout(LayoutContext layoutContext) {
|
|
|
|
layoutChildren(layoutContext);
|
|
|
|
|
2018-04-10 23:37:22 +00:00
|
|
|
for (auto child : getLayoutableChildNodes()) {
|
2018-03-19 02:04:20 +00:00
|
|
|
if (!child->getHasNewLayout()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-04-10 23:37:09 +00:00
|
|
|
child->ensureUnsealed();
|
2018-04-10 19:45:35 +00:00
|
|
|
|
2018-03-19 02:04:20 +00:00
|
|
|
// The assumption:
|
|
|
|
// All `sealed` children were replaced with not-yet-sealed clones
|
|
|
|
// somewhere in `layoutChildren`.
|
|
|
|
auto nonConstChild = std::const_pointer_cast<LayoutableShadowNode>(child);
|
|
|
|
|
|
|
|
nonConstChild->setHasNewLayout(false);
|
|
|
|
|
|
|
|
const LayoutMetrics childLayoutMetrics = nonConstChild->getLayoutMetrics();
|
2018-04-10 23:37:19 +00:00
|
|
|
if (childLayoutMetrics.displayType == DisplayType::None) {
|
2018-03-19 02:04:20 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
LayoutContext childLayoutContext = LayoutContext(layoutContext);
|
|
|
|
childLayoutContext.absolutePosition += childLayoutMetrics.frame.origin;
|
|
|
|
|
|
|
|
nonConstChild->layout(layoutContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayoutableShadowNode::layoutChildren(LayoutContext layoutContext) {
|
|
|
|
// Default implementation does nothing.
|
|
|
|
}
|
|
|
|
|
2018-04-27 00:51:35 +00:00
|
|
|
SharedDebugStringConvertibleList LayoutableShadowNode::getDebugProps() const {
|
|
|
|
SharedDebugStringConvertibleList list = {};
|
|
|
|
|
|
|
|
if (getHasNewLayout()) {
|
|
|
|
list.push_back(std::make_shared<DebugStringConvertibleItem>("hasNewLayout"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!getIsLayoutClean()) {
|
|
|
|
list.push_back(std::make_shared<DebugStringConvertibleItem>("dirty"));
|
|
|
|
}
|
|
|
|
|
|
|
|
LayoutMetrics layoutMetrics = getLayoutMetrics();
|
|
|
|
LayoutMetrics defaultLayoutMetrics = LayoutMetrics();
|
|
|
|
|
2018-05-14 22:43:48 +00:00
|
|
|
list.push_back(std::make_shared<DebugStringConvertibleItem>("frame", toString(layoutMetrics.frame)));
|
2018-04-27 00:51:35 +00:00
|
|
|
|
|
|
|
if (layoutMetrics.borderWidth != defaultLayoutMetrics.borderWidth) {
|
2018-05-14 22:43:48 +00:00
|
|
|
list.push_back(std::make_shared<DebugStringConvertibleItem>("borderWidth", toString(layoutMetrics.borderWidth)));
|
2018-04-27 00:51:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (layoutMetrics.contentInsets != defaultLayoutMetrics.contentInsets) {
|
2018-05-14 22:43:48 +00:00
|
|
|
list.push_back(std::make_shared<DebugStringConvertibleItem>("contentInsets", toString(layoutMetrics.contentInsets)));
|
2018-04-27 00:51:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (layoutMetrics.displayType == DisplayType::None) {
|
|
|
|
list.push_back(std::make_shared<DebugStringConvertibleItem>("hidden"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (layoutMetrics.layoutDirection == LayoutDirection::RightToLeft) {
|
|
|
|
list.push_back(std::make_shared<DebugStringConvertibleItem>("rtl"));
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2018-03-19 02:04:20 +00:00
|
|
|
} // namespace react
|
|
|
|
} // namespace facebook
|