Skip to content

Commit 42be1aa

Browse files
sherginfacebook-github-bot
authored andcommitted
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
1 parent b592c86 commit 42be1aa

File tree

3 files changed

+44
-10
lines changed

3 files changed

+44
-10
lines changed

ReactCommon/fabric/element/ComponentBuilder.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ class ComponentBuilder final {
2929
ComponentBuilder(
3030
ComponentDescriptorRegistry::Shared const &componentDescriptorRegistry);
3131

32+
/*
33+
* Copyable and movable.
34+
*/
35+
ComponentBuilder(ComponentBuilder const &componentBuilder) = default;
36+
ComponentBuilder(ComponentBuilder &&componentBuilder) noexcept = default;
37+
ComponentBuilder &operator=(ComponentBuilder const &other) = default;
38+
ComponentBuilder &operator=(ComponentBuilder &&other) = default;
39+
3240
/*
3341
* Builds a `ShadowNode` tree with given `Element` tree using stored
3442
* `ComponentDescriptorRegistry`.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
#include <react/components/root/RootComponentDescriptor.h>
11+
#include <react/components/view/ViewComponentDescriptor.h>
12+
#include <react/element/ComponentBuilder.h>
13+
#include <react/uimanager/ComponentDescriptorProviderRegistry.h>
14+
15+
namespace facebook {
16+
namespace react {
17+
18+
extern ComponentBuilder simpleComponentBuilder() {
19+
ComponentDescriptorProviderRegistry componentDescriptorProviderRegistry{};
20+
auto eventDispatcher = EventDispatcher::Shared{};
21+
auto componentDescriptorRegistry =
22+
componentDescriptorProviderRegistry.createComponentDescriptorRegistry(
23+
ComponentDescriptorParameters{eventDispatcher, nullptr, nullptr});
24+
25+
componentDescriptorProviderRegistry.add(
26+
concreteComponentDescriptorProvider<RootComponentDescriptor>());
27+
componentDescriptorProviderRegistry.add(
28+
concreteComponentDescriptorProvider<ViewComponentDescriptor>());
29+
30+
return ComponentBuilder{componentDescriptorRegistry};
31+
}
32+
33+
} // namespace react
34+
} // namespace facebook

ReactCommon/fabric/element/tests/ElementTest.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,13 @@
1212
#include <react/components/view/ViewComponentDescriptor.h>
1313
#include <react/element/ComponentBuilder.h>
1414
#include <react/element/Element.h>
15+
#include <react/element/testUtils.h>
1516
#include <react/uimanager/ComponentDescriptorProviderRegistry.h>
1617

1718
using namespace facebook::react;
1819

1920
TEST(ElementTest, testNormalCases) {
20-
ComponentDescriptorProviderRegistry componentDescriptorProviderRegistry{};
21-
auto eventDispatcher = EventDispatcher::Shared{};
22-
auto componentDescriptorRegistry =
23-
componentDescriptorProviderRegistry.createComponentDescriptorRegistry(
24-
ComponentDescriptorParameters{eventDispatcher, nullptr, nullptr});
25-
26-
componentDescriptorProviderRegistry.add(
27-
concreteComponentDescriptorProvider<ViewComponentDescriptor>());
28-
29-
auto builder = ComponentBuilder{componentDescriptorRegistry};
21+
auto builder = simpleComponentBuilder();
3022

3123
auto shadowNodeA = std::shared_ptr<ViewShadowNode const>{};
3224
auto shadowNodeAA = std::shared_ptr<ViewShadowNode const>{};

0 commit comments

Comments
 (0)