Fabric: Making ComponentBuilder copyable and movable

Summary:
It's useful property to have.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D19596280

fbshipit-source-id: 5b60cc4f7c65c3458ff35ffa2dfaafce79dc985a
This commit is contained in:
Valentin Shergin
2020-01-30 19:45:38 -08:00
committed by Facebook Github Bot
parent b592c863ef
commit 42be1aad82
3 changed files with 44 additions and 10 deletions
@@ -29,6 +29,14 @@ class ComponentBuilder final {
ComponentBuilder(
ComponentDescriptorRegistry::Shared const &componentDescriptorRegistry);
/*
* Copyable and movable.
*/
ComponentBuilder(ComponentBuilder const &componentBuilder) = default;
ComponentBuilder(ComponentBuilder &&componentBuilder) noexcept = default;
ComponentBuilder &operator=(ComponentBuilder const &other) = default;
ComponentBuilder &operator=(ComponentBuilder &&other) = default;
/*
* Builds a `ShadowNode` tree with given `Element` tree using stored
* `ComponentDescriptorRegistry`.
+34
View File
@@ -0,0 +1,34 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* 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 <react/components/root/RootComponentDescriptor.h>
#include <react/components/view/ViewComponentDescriptor.h>
#include <react/element/ComponentBuilder.h>
#include <react/uimanager/ComponentDescriptorProviderRegistry.h>
namespace facebook {
namespace react {
extern ComponentBuilder simpleComponentBuilder() {
ComponentDescriptorProviderRegistry componentDescriptorProviderRegistry{};
auto eventDispatcher = EventDispatcher::Shared{};
auto componentDescriptorRegistry =
componentDescriptorProviderRegistry.createComponentDescriptorRegistry(
ComponentDescriptorParameters{eventDispatcher, nullptr, nullptr});
componentDescriptorProviderRegistry.add(
concreteComponentDescriptorProvider<RootComponentDescriptor>());
componentDescriptorProviderRegistry.add(
concreteComponentDescriptorProvider<ViewComponentDescriptor>());
return ComponentBuilder{componentDescriptorRegistry};
}
} // namespace react
} // namespace facebook
@@ -12,21 +12,13 @@
#include <react/components/view/ViewComponentDescriptor.h>
#include <react/element/ComponentBuilder.h>
#include <react/element/Element.h>
#include <react/element/testUtils.h>
#include <react/uimanager/ComponentDescriptorProviderRegistry.h>
using namespace facebook::react;
TEST(ElementTest, testNormalCases) {
ComponentDescriptorProviderRegistry componentDescriptorProviderRegistry{};
auto eventDispatcher = EventDispatcher::Shared{};
auto componentDescriptorRegistry =
componentDescriptorProviderRegistry.createComponentDescriptorRegistry(
ComponentDescriptorParameters{eventDispatcher, nullptr, nullptr});
componentDescriptorProviderRegistry.add(
concreteComponentDescriptorProvider<ViewComponentDescriptor>());
auto builder = ComponentBuilder{componentDescriptorRegistry};
auto builder = simpleComponentBuilder();
auto shadowNodeA = std::shared_ptr<ViewShadowNode const>{};
auto shadowNodeAA = std::shared_ptr<ViewShadowNode const>{};