Fabric: Removing `Scheduler::rootComponentDescriptor_`

Summary:
This diff simplifies `ShadowTree` constructor by removing `rootComponentDescriptor` argument. It was previously stored and supplied by `Scheduler`; now `ShadowTree` class allocates one instance of it for all instances of `ShadowTree`. The `RootComponentDescriptor` instance of it is only needed to clone a `RootShadowNode` instance; it cannot issue events, state updates, or anything like that because it does not have React counterpart.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: JoshuaGross, sammy-SC

Differential Revision: D26048466

fbshipit-source-id: ec02b1b4bcc917efe17cef58112fa870b341c85f
This commit is contained in:
Valentin Shergin 2021-01-25 14:09:28 -08:00 коммит произвёл Facebook GitHub Bot
Родитель 47cd7edf14
Коммит 9117840f1c
5 изменённых файлов: 7 добавлений и 14 удалений

Просмотреть файл

@ -222,22 +222,26 @@ ShadowTree::ShadowTree(
SurfaceId surfaceId, SurfaceId surfaceId,
LayoutConstraints const &layoutConstraints, LayoutConstraints const &layoutConstraints,
LayoutContext const &layoutContext, LayoutContext const &layoutContext,
RootComponentDescriptor const &rootComponentDescriptor,
ShadowTreeDelegate const &delegate, ShadowTreeDelegate const &delegate,
std::weak_ptr<MountingOverrideDelegate const> mountingOverrideDelegate) std::weak_ptr<MountingOverrideDelegate const> mountingOverrideDelegate)
: surfaceId_(surfaceId), delegate_(delegate) { : surfaceId_(surfaceId), delegate_(delegate) {
const auto noopEventEmitter = std::make_shared<const ViewEventEmitter>( const auto noopEventEmitter = std::make_shared<const ViewEventEmitter>(
nullptr, -1, std::shared_ptr<const EventDispatcher>()); nullptr, -1, std::shared_ptr<const EventDispatcher>());
static auto globalRootComponentDescriptor =
std::make_unique<RootComponentDescriptor const>(
ComponentDescriptorParameters{
EventDispatcher::Shared{}, nullptr, nullptr});
const auto props = std::make_shared<const RootProps>( const auto props = std::make_shared<const RootProps>(
*RootShadowNode::defaultSharedProps(), layoutConstraints, layoutContext); *RootShadowNode::defaultSharedProps(), layoutConstraints, layoutContext);
auto const fragment = auto const fragment =
ShadowNodeFamilyFragment{surfaceId, surfaceId, noopEventEmitter}; ShadowNodeFamilyFragment{surfaceId, surfaceId, noopEventEmitter};
auto family = rootComponentDescriptor.createFamily(fragment, nullptr); auto family = globalRootComponentDescriptor->createFamily(fragment, nullptr);
auto rootShadowNode = std::static_pointer_cast<const RootShadowNode>( auto rootShadowNode = std::static_pointer_cast<const RootShadowNode>(
rootComponentDescriptor.createShadowNode( globalRootComponentDescriptor->createShadowNode(
ShadowNodeFragment{ ShadowNodeFragment{
/* .props = */ props, /* .props = */ props,
}, },

Просмотреть файл

@ -67,7 +67,6 @@ class ShadowTree final {
SurfaceId surfaceId, SurfaceId surfaceId,
LayoutConstraints const &layoutConstraints, LayoutConstraints const &layoutConstraints,
LayoutContext const &layoutContext, LayoutContext const &layoutContext,
RootComponentDescriptor const &rootComponentDescriptor,
ShadowTreeDelegate const &delegate, ShadowTreeDelegate const &delegate,
std::weak_ptr<MountingOverrideDelegate const> mountingOverrideDelegate); std::weak_ptr<MountingOverrideDelegate const> mountingOverrideDelegate);

Просмотреть файл

@ -10,7 +10,6 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h> #include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
#include <react/renderer/components/root/RootComponentDescriptor.h>
#include <react/renderer/components/view/ViewComponentDescriptor.h> #include <react/renderer/components/view/ViewComponentDescriptor.h>
#include <react/renderer/element/ComponentBuilder.h> #include <react/renderer/element/ComponentBuilder.h>
#include <react/renderer/element/Element.h> #include <react/renderer/element/Element.h>
@ -95,14 +94,10 @@ TEST(StateReconciliationTest, testStateReconciliation) {
auto &family = shadowNodeAB->getFamily(); auto &family = shadowNodeAB->getFamily();
auto state1 = shadowNodeAB->getState(); auto state1 = shadowNodeAB->getState();
auto shadowTreeDelegate = DummyShadowTreeDelegate{}; auto shadowTreeDelegate = DummyShadowTreeDelegate{};
auto eventDispatcher = EventDispatcher::Shared{};
auto rootComponentDescriptor =
ComponentDescriptorParameters{eventDispatcher, nullptr, nullptr};
ShadowTree shadowTree{ ShadowTree shadowTree{
SurfaceId{11}, SurfaceId{11},
LayoutConstraints{}, LayoutConstraints{},
LayoutContext{}, LayoutContext{},
rootComponentDescriptor,
shadowTreeDelegate, shadowTreeDelegate,
{}}; {}};

Просмотреть файл

@ -76,9 +76,6 @@ Scheduler::Scheduler(
componentDescriptorRegistry_ = schedulerToolbox.componentRegistryFactory( componentDescriptorRegistry_ = schedulerToolbox.componentRegistryFactory(
eventDispatcher, schedulerToolbox.contextContainer); eventDispatcher, schedulerToolbox.contextContainer);
rootComponentDescriptor_ = std::make_unique<const RootComponentDescriptor>(
ComponentDescriptorParameters{eventDispatcher, nullptr, nullptr});
uiManager->setBackgroundExecutor(schedulerToolbox.backgroundExecutor); uiManager->setBackgroundExecutor(schedulerToolbox.backgroundExecutor);
uiManager->setDelegate(this); uiManager->setDelegate(this);
uiManager->setComponentDescriptorRegistry(componentDescriptorRegistry_); uiManager->setComponentDescriptorRegistry(componentDescriptorRegistry_);
@ -188,7 +185,6 @@ void Scheduler::startSurface(
surfaceId, surfaceId,
layoutConstraints, layoutConstraints,
layoutContext, layoutContext,
*rootComponentDescriptor_,
*uiManager_, *uiManager_,
mountingOverrideDelegate); mountingOverrideDelegate);

Просмотреть файл

@ -123,7 +123,6 @@ class Scheduler final : public UIManagerDelegate {
private: private:
SchedulerDelegate *delegate_; SchedulerDelegate *delegate_;
SharedComponentDescriptorRegistry componentDescriptorRegistry_; SharedComponentDescriptorRegistry componentDescriptorRegistry_;
std::unique_ptr<const RootComponentDescriptor> rootComponentDescriptor_;
RuntimeExecutor runtimeExecutor_; RuntimeExecutor runtimeExecutor_;
std::shared_ptr<UIManager> uiManager_; std::shared_ptr<UIManager> uiManager_;
std::shared_ptr<const ReactNativeConfig> reactNativeConfig_; std::shared_ptr<const ReactNativeConfig> reactNativeConfig_;