2018-04-27 00:51:29 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <fabric/core/ConcreteShadowNode.h>
|
|
|
|
#include <fabric/core/LayoutableShadowNode.h>
|
|
|
|
#include <fabric/core/ShadowNode.h>
|
|
|
|
#include <fabric/debug/DebugStringConvertibleItem.h>
|
|
|
|
#include <fabric/view/AccessibleShadowNode.h>
|
2018-06-09 20:02:55 +00:00
|
|
|
#include <fabric/view/ViewEventEmitter.h>
|
2018-04-27 00:51:29 +00:00
|
|
|
#include <fabric/view/ViewProps.h>
|
|
|
|
#include <fabric/view/YogaLayoutableShadowNode.h>
|
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace react {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Template for all <View>-like classes (classes which have all same props
|
|
|
|
* as <View> and similar basic behaviour).
|
|
|
|
* For example: <Paragraph>, <Image>, but not <Text>, <RawText>.
|
|
|
|
*/
|
2018-06-09 20:02:55 +00:00
|
|
|
template <typename ViewPropsT = ViewProps, typename ViewEventEmitterT = ViewEventEmitter>
|
2018-04-27 00:51:29 +00:00
|
|
|
class ConcreteViewShadowNode:
|
2018-06-09 20:02:55 +00:00
|
|
|
public ConcreteShadowNode<ViewPropsT, ViewEventEmitterT>,
|
2018-04-27 00:51:29 +00:00
|
|
|
public AccessibleShadowNode,
|
|
|
|
public YogaLayoutableShadowNode {
|
|
|
|
|
|
|
|
static_assert(std::is_base_of<ViewProps, ViewPropsT>::value, "ViewPropsT must be a descendant of ViewProps");
|
|
|
|
static_assert(std::is_base_of<YogaStylableProps, ViewPropsT>::value, "ViewPropsT must be a descendant of YogaStylableProps");
|
|
|
|
static_assert(std::is_base_of<AccessibilityProps, ViewPropsT>::value, "ViewPropsT must be a descendant of AccessibilityProps");
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
using ConcreteViewProps = ViewPropsT;
|
|
|
|
using SharedConcreteViewProps = std::shared_ptr<const ViewPropsT>;
|
2018-06-09 20:02:55 +00:00
|
|
|
using ConcreteViewEventEmitter = ViewEventEmitterT;
|
|
|
|
using SharedConcreteViewEventEmitter = std::shared_ptr<const ViewEventEmitterT>;
|
2018-04-27 00:51:29 +00:00
|
|
|
using SharedConcreteViewShadowNode = std::shared_ptr<const ConcreteViewShadowNode>;
|
|
|
|
|
|
|
|
ConcreteViewShadowNode(
|
|
|
|
const Tag &tag,
|
|
|
|
const Tag &rootTag,
|
2018-05-18 03:03:42 +00:00
|
|
|
const SharedConcreteViewProps &props,
|
2018-06-09 20:02:55 +00:00
|
|
|
const SharedConcreteViewEventEmitter &eventEmitter,
|
2018-05-18 03:03:42 +00:00
|
|
|
const SharedShadowNodeSharedList &children,
|
|
|
|
const ShadowNodeCloneFunction &cloneFunction
|
2018-04-27 00:51:29 +00:00
|
|
|
):
|
2018-06-09 20:02:55 +00:00
|
|
|
ConcreteShadowNode<ViewPropsT, ViewEventEmitterT>(
|
2018-04-27 00:51:29 +00:00
|
|
|
tag,
|
|
|
|
rootTag,
|
|
|
|
props,
|
2018-06-09 20:02:55 +00:00
|
|
|
eventEmitter,
|
2018-04-27 00:51:29 +00:00
|
|
|
children,
|
|
|
|
cloneFunction
|
|
|
|
),
|
|
|
|
AccessibleShadowNode(
|
|
|
|
props
|
|
|
|
),
|
|
|
|
YogaLayoutableShadowNode(
|
|
|
|
props,
|
|
|
|
children
|
|
|
|
) {};
|
|
|
|
|
|
|
|
ConcreteViewShadowNode(
|
|
|
|
const SharedConcreteViewShadowNode &shadowNode,
|
2018-05-18 03:03:42 +00:00
|
|
|
const SharedConcreteViewProps &props,
|
2018-06-09 20:02:55 +00:00
|
|
|
const SharedConcreteViewEventEmitter &eventEmitter,
|
2018-05-18 03:03:42 +00:00
|
|
|
const SharedShadowNodeSharedList &children
|
2018-04-27 00:51:29 +00:00
|
|
|
):
|
2018-06-09 20:02:55 +00:00
|
|
|
ConcreteShadowNode<ViewPropsT, ViewEventEmitterT>(
|
2018-04-27 00:51:29 +00:00
|
|
|
shadowNode,
|
|
|
|
props,
|
2018-06-09 20:02:55 +00:00
|
|
|
eventEmitter,
|
2018-04-27 00:51:29 +00:00
|
|
|
children
|
|
|
|
),
|
|
|
|
AccessibleShadowNode(
|
|
|
|
shadowNode,
|
|
|
|
props
|
|
|
|
),
|
|
|
|
YogaLayoutableShadowNode(
|
|
|
|
shadowNode,
|
|
|
|
props,
|
|
|
|
children
|
|
|
|
) {};
|
|
|
|
|
|
|
|
void appendChild(const SharedShadowNode &child) {
|
|
|
|
ensureUnsealed();
|
|
|
|
|
|
|
|
ShadowNode::appendChild(child);
|
|
|
|
|
|
|
|
auto yogaLayoutableChild = std::dynamic_pointer_cast<const YogaLayoutableShadowNode>(child);
|
|
|
|
if (yogaLayoutableChild) {
|
|
|
|
YogaLayoutableShadowNode::appendChild(yogaLayoutableChild);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SharedLayoutableShadowNode cloneAndReplaceChild(const SharedLayoutableShadowNode &child) override {
|
|
|
|
ensureUnsealed();
|
|
|
|
|
|
|
|
auto childShadowNode = std::dynamic_pointer_cast<const ShadowNode>(child);
|
|
|
|
assert(childShadowNode);
|
|
|
|
auto childShadowNodeClone = childShadowNode->clone();
|
|
|
|
ShadowNode::replaceChild(childShadowNode, childShadowNodeClone);
|
|
|
|
return std::dynamic_pointer_cast<const LayoutableShadowNode>(childShadowNodeClone);
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Equality
|
|
|
|
|
|
|
|
bool operator==(const ShadowNode& rhs) const override {
|
|
|
|
if (!ShadowNode::operator==(rhs)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-06-22 14:28:36 +00:00
|
|
|
const auto &other = static_cast<const ConcreteViewShadowNode&>(rhs);
|
2018-04-27 00:51:29 +00:00
|
|
|
return getLayoutMetrics() == other.getLayoutMetrics();
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - DebugStringConvertible
|
|
|
|
|
|
|
|
SharedDebugStringConvertibleList getDebugProps() const override {
|
|
|
|
SharedDebugStringConvertibleList list = {};
|
|
|
|
|
|
|
|
auto basePropsList = ShadowNode::getDebugProps();
|
|
|
|
std::move(basePropsList.begin(), basePropsList.end(), std::back_inserter(list));
|
|
|
|
|
2018-04-27 00:51:35 +00:00
|
|
|
list.push_back(std::make_shared<DebugStringConvertibleItem>("layout", "", LayoutableShadowNode::getDebugProps()));
|
2018-04-27 00:51:29 +00:00
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2018-05-18 03:03:41 +00:00
|
|
|
protected:
|
2018-04-27 00:51:29 +00:00
|
|
|
|
|
|
|
#pragma mark - LayoutableShadowNode
|
|
|
|
|
|
|
|
SharedLayoutableShadowNodeList getLayoutableChildNodes() const override {
|
|
|
|
SharedLayoutableShadowNodeList sharedLayoutableShadowNodeList = {};
|
|
|
|
for (auto child : *ShadowNode::children_) {
|
|
|
|
const SharedLayoutableShadowNode layoutableShadowNode = std::dynamic_pointer_cast<const LayoutableShadowNode>(child);
|
|
|
|
if (!layoutableShadowNode) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
sharedLayoutableShadowNodeList.push_back(layoutableShadowNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
return sharedLayoutableShadowNodeList;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace react
|
|
|
|
} // namespace facebook
|