Fabric: Element<X>::children() now accepts children of any Element<> type

Summary:
Before this change `Element<X>` cannot have children of `Element<Y>` which was wrong because we don't have such limitation in Fabric.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D19596283

fbshipit-source-id: 9002f5dd42b3d05e7cf492499499399c97b58152
This commit is contained in:
Valentin Shergin
2020-01-30 19:45:39 -08:00
committed by Facebook Github Bot
parent 42be1aad82
commit d64bf2c4f8
2 changed files with 14 additions and 7 deletions
+9 -2
View File
@@ -48,6 +48,13 @@ class Element final {
fragment_.props = ShadowNodeT::defaultSharedProps();
}
/*
* Converts to `ElementFragment` object.
*/
operator ElementFragment() {
return fragment_;
}
/*
* Sets `tag`.
*/
@@ -83,11 +90,11 @@ class Element final {
/*
* Sets children.
*/
Element &children(std::vector<Element> children) {
Element &children(std::vector<ElementFragment> children) {
auto fragments = ElementFragment::List{};
fragments.reserve(children.size());
for (auto const &child : children) {
fragments.push_back(child.fragment_);
fragments.push_back(child);
}
fragment_.children = fragments;
return *this;
@@ -9,6 +9,7 @@
#include <gtest/gtest.h>
#include <react/components/root/RootComponentDescriptor.h>
#include <react/components/view/ViewComponentDescriptor.h>
#include <react/element/ComponentBuilder.h>
#include <react/element/Element.h>
@@ -20,7 +21,7 @@ using namespace facebook::react;
TEST(ElementTest, testNormalCases) {
auto builder = simpleComponentBuilder();
auto shadowNodeA = std::shared_ptr<ViewShadowNode const>{};
auto shadowNodeA = std::shared_ptr<RootShadowNode const>{};
auto shadowNodeAA = std::shared_ptr<ViewShadowNode const>{};
auto shadowNodeAB = std::shared_ptr<ViewShadowNode const>{};
auto shadowNodeABA = std::shared_ptr<ViewShadowNode const>{};
@@ -30,16 +31,15 @@ TEST(ElementTest, testNormalCases) {
// clang-format off
auto element =
Element<ViewShadowNode>()
Element<RootShadowNode>()
.reference(shadowNodeA)
.tag(1)
.props([]() {
auto props = std::make_shared<ViewProps>();
props->zIndex = 42;
auto props = std::make_shared<RootProps>();
props->nativeId = "node A";
return props;
})
.finalize([](ViewShadowNode &shadowNode){
.finalize([](RootShadowNode &shadowNode){
shadowNode.sealRecursive();
})
.children({