diff --git a/ReactCommon/fabric/components/root/RootComponentDescriptor.h b/ReactCommon/fabric/components/root/RootComponentDescriptor.h new file mode 100644 index 0000000000..47a5c9471b --- /dev/null +++ b/ReactCommon/fabric/components/root/RootComponentDescriptor.h @@ -0,0 +1,19 @@ +/** + * 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 +#include + +namespace facebook { +namespace react { + +using RootComponentDescriptor = ConcreteComponentDescriptor; + +} // namespace react +} // namespace facebook diff --git a/ReactCommon/fabric/components/root/RootProps.cpp b/ReactCommon/fabric/components/root/RootProps.cpp index d0efb19400..134dba48b5 100644 --- a/ReactCommon/fabric/components/root/RootProps.cpp +++ b/ReactCommon/fabric/components/root/RootProps.cpp @@ -32,6 +32,11 @@ static YGStyle yogaStyleFromLayoutConstraints( return yogaStyle; } +RootProps::RootProps(const RootProps &sourceProps, const RawProps &rawProps) { + // `RootProps` cannot be constructed from `RawProps`. + assert(false); +} + RootProps::RootProps( const RootProps &sourceProps, const LayoutConstraints &layoutConstraints, diff --git a/ReactCommon/fabric/components/root/RootProps.h b/ReactCommon/fabric/components/root/RootProps.h index 1ef3068eaf..bdeaa7014d 100644 --- a/ReactCommon/fabric/components/root/RootProps.h +++ b/ReactCommon/fabric/components/root/RootProps.h @@ -23,6 +23,7 @@ using SharedRootProps = std::shared_ptr; class RootProps final : public ViewProps { public: RootProps() = default; + RootProps(const RootProps &sourceProps, const RawProps &rawProps); RootProps( const RootProps &sourceProps, const LayoutConstraints &layoutConstraints, diff --git a/ReactCommon/fabric/uimanager/Scheduler.cpp b/ReactCommon/fabric/uimanager/Scheduler.cpp index 1dd618b290..56f7939a2d 100644 --- a/ReactCommon/fabric/uimanager/Scheduler.cpp +++ b/ReactCommon/fabric/uimanager/Scheduler.cpp @@ -62,6 +62,9 @@ Scheduler::Scheduler( componentDescriptorRegistry_ = buildRegistryFunction(eventDispatcher, contextContainer); + rootComponentDescriptor_ = + std::make_unique(eventDispatcher); + uiManagerRef.setDelegate(this); uiManagerRef.setShadowTreeRegistry(&shadowTreeRegistry_); uiManagerRef.setComponentDescriptorRegistry(componentDescriptorRegistry_); @@ -83,8 +86,8 @@ void Scheduler::startSurface( const LayoutContext &layoutContext) const { SystraceSection s("Scheduler::startSurface"); - auto shadowTree = - std::make_unique(surfaceId, layoutConstraints, layoutContext); + auto shadowTree = std::make_unique( + surfaceId, layoutConstraints, layoutContext, *rootComponentDescriptor_); shadowTree->setDelegate(this); shadowTreeRegistry_.add(std::move(shadowTree)); diff --git a/ReactCommon/fabric/uimanager/Scheduler.h b/ReactCommon/fabric/uimanager/Scheduler.h index 1eff117f32..6bad79fc14 100644 --- a/ReactCommon/fabric/uimanager/Scheduler.h +++ b/ReactCommon/fabric/uimanager/Scheduler.h @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -99,6 +100,7 @@ class Scheduler final : public UIManagerDelegate, public ShadowTreeDelegate { private: SchedulerDelegate *delegate_; SharedComponentDescriptorRegistry componentDescriptorRegistry_; + std::unique_ptr rootComponentDescriptor_; ShadowTreeRegistry shadowTreeRegistry_; RuntimeExecutor runtimeExecutor_; std::shared_ptr uiManagerBinding_; diff --git a/ReactCommon/fabric/uimanager/ShadowTree.cpp b/ReactCommon/fabric/uimanager/ShadowTree.cpp index 6e5e722a42..f16c948a5c 100644 --- a/ReactCommon/fabric/uimanager/ShadowTree.cpp +++ b/ReactCommon/fabric/uimanager/ShadowTree.cpp @@ -5,6 +5,7 @@ #include "ShadowTree.h" +#include #include #include #include @@ -79,7 +80,8 @@ static void updateMountedFlag( ShadowTree::ShadowTree( SurfaceId surfaceId, const LayoutConstraints &layoutConstraints, - const LayoutContext &layoutContext) + const LayoutContext &layoutContext, + const RootComponentDescriptor &rootComponentDescriptor) : surfaceId_(surfaceId) { const auto noopEventEmitter = std::make_shared( nullptr, -1, std::shared_ptr()); @@ -87,16 +89,13 @@ ShadowTree::ShadowTree( const auto props = std::make_shared( *RootShadowNode::defaultSharedProps(), layoutConstraints, layoutContext); - rootShadowNode_ = std::make_shared( - ShadowNodeFragment{ + rootShadowNode_ = std::static_pointer_cast( + rootComponentDescriptor.createShadowNode(ShadowNodeFragment{ .tag = surfaceId, .rootTag = surfaceId, .props = props, .eventEmitter = noopEventEmitter, - }, - [](const ShadowNode &shadowNode, const ShadowNodeFragment &fragment) { - return std::make_shared(shadowNode, fragment); - }); + })); } ShadowTree::~ShadowTree() { diff --git a/ReactCommon/fabric/uimanager/ShadowTree.h b/ReactCommon/fabric/uimanager/ShadowTree.h index 03e9de4117..41f328292e 100644 --- a/ReactCommon/fabric/uimanager/ShadowTree.h +++ b/ReactCommon/fabric/uimanager/ShadowTree.h @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -33,7 +34,8 @@ class ShadowTree final { ShadowTree( SurfaceId surfaceId, const LayoutConstraints &layoutConstraints, - const LayoutContext &layoutContext); + const LayoutContext &layoutContext, + const RootComponentDescriptor &rootComponentDescriptor); ~ShadowTree();