mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-01-12 22:50:10 +08:00
Fabric: Using RootComponentDescriptor to manage RootShadowNode in ShadowTree
Summary: We need this change to migrate away `cloneFunction` (to a pointer to ComponentDescriptor) inside ShadowNode. Reviewed By: mdvacca Differential Revision: D14249197 fbshipit-source-id: 773edcf40e17989886e2c5d3955823a0dbf3857a
This commit is contained in:
committed by
Facebook Github Bot
parent
0ed988f182
commit
aed352246e
19
ReactCommon/fabric/components/root/RootComponentDescriptor.h
Normal file
19
ReactCommon/fabric/components/root/RootComponentDescriptor.h
Normal file
@@ -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 <react/components/root/RootShadowNode.h>
|
||||
#include <react/core/ConcreteComponentDescriptor.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
using RootComponentDescriptor = ConcreteComponentDescriptor<RootShadowNode>;
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
@@ -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,
|
||||
|
||||
@@ -23,6 +23,7 @@ using SharedRootProps = std::shared_ptr<const RootProps>;
|
||||
class RootProps final : public ViewProps {
|
||||
public:
|
||||
RootProps() = default;
|
||||
RootProps(const RootProps &sourceProps, const RawProps &rawProps);
|
||||
RootProps(
|
||||
const RootProps &sourceProps,
|
||||
const LayoutConstraints &layoutConstraints,
|
||||
|
||||
@@ -62,6 +62,9 @@ Scheduler::Scheduler(
|
||||
componentDescriptorRegistry_ =
|
||||
buildRegistryFunction(eventDispatcher, contextContainer);
|
||||
|
||||
rootComponentDescriptor_ =
|
||||
std::make_unique<const RootComponentDescriptor>(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<ShadowTree>(surfaceId, layoutConstraints, layoutContext);
|
||||
auto shadowTree = std::make_unique<ShadowTree>(
|
||||
surfaceId, layoutConstraints, layoutContext, *rootComponentDescriptor_);
|
||||
shadowTree->setDelegate(this);
|
||||
|
||||
shadowTreeRegistry_.add(std::move(shadowTree));
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
#include <react/components/root/RootComponentDescriptor.h>
|
||||
#include <react/config/ReactNativeConfig.h>
|
||||
#include <react/core/ComponentDescriptor.h>
|
||||
#include <react/core/LayoutConstraints.h>
|
||||
@@ -99,6 +100,7 @@ class Scheduler final : public UIManagerDelegate, public ShadowTreeDelegate {
|
||||
private:
|
||||
SchedulerDelegate *delegate_;
|
||||
SharedComponentDescriptorRegistry componentDescriptorRegistry_;
|
||||
std::unique_ptr<const RootComponentDescriptor> rootComponentDescriptor_;
|
||||
ShadowTreeRegistry shadowTreeRegistry_;
|
||||
RuntimeExecutor runtimeExecutor_;
|
||||
std::shared_ptr<UIManagerBinding> uiManagerBinding_;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "ShadowTree.h"
|
||||
|
||||
#include <react/components/root/RootComponentDescriptor.h>
|
||||
#include <react/core/LayoutContext.h>
|
||||
#include <react/core/LayoutPrimitives.h>
|
||||
#include <react/debug/SystraceSection.h>
|
||||
@@ -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<const ViewEventEmitter>(
|
||||
nullptr, -1, std::shared_ptr<const EventDispatcher>());
|
||||
@@ -87,16 +89,13 @@ ShadowTree::ShadowTree(
|
||||
const auto props = std::make_shared<const RootProps>(
|
||||
*RootShadowNode::defaultSharedProps(), layoutConstraints, layoutContext);
|
||||
|
||||
rootShadowNode_ = std::make_shared<RootShadowNode>(
|
||||
ShadowNodeFragment{
|
||||
rootShadowNode_ = std::static_pointer_cast<const RootShadowNode>(
|
||||
rootComponentDescriptor.createShadowNode(ShadowNodeFragment{
|
||||
.tag = surfaceId,
|
||||
.rootTag = surfaceId,
|
||||
.props = props,
|
||||
.eventEmitter = noopEventEmitter,
|
||||
},
|
||||
[](const ShadowNode &shadowNode, const ShadowNodeFragment &fragment) {
|
||||
return std::make_shared<RootShadowNode>(shadowNode, fragment);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
ShadowTree::~ShadowTree() {
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <memory>
|
||||
#include <shared_mutex>
|
||||
|
||||
#include <react/components/root/RootComponentDescriptor.h>
|
||||
#include <react/components/root/RootShadowNode.h>
|
||||
#include <react/core/LayoutConstraints.h>
|
||||
#include <react/core/ReactPrimitives.h>
|
||||
@@ -33,7 +34,8 @@ class ShadowTree final {
|
||||
ShadowTree(
|
||||
SurfaceId surfaceId,
|
||||
const LayoutConstraints &layoutConstraints,
|
||||
const LayoutContext &layoutContext);
|
||||
const LayoutContext &layoutContext,
|
||||
const RootComponentDescriptor &rootComponentDescriptor);
|
||||
|
||||
~ShadowTree();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user