mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: This is the first diff in the journey of removing `enable_shared_from_this` from `ShadowNode` class. In general, using `enable_shared_from_this` is fine, it's a normal standard feature and there is nothing wrong with that... besides the fact that using this thing is usually an indication of overall poor design. In Fabric, we don't really have a good reason for that, I think in all cases it can be avoided, so I think we should remove that. Removing that is also code-size and perf win. This particular diff changes the signature of `RootShadowNode::clone()` which allows removing the necessity of usage `.shared_from_this()` from callsites. The rest changes are purely cosmetical. Changelog: [Internal] Small Fabric-specific optimization. Reviewed By: sammy-SC Differential Revision: D17973958 fbshipit-source-id: 5539ceff9d11b4281a6ebe8d80e90d6bd90e44d8
65 lines
1.7 KiB
C++
65 lines
1.7 KiB
C++
/*
|
|
* 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 <memory>
|
|
|
|
#include <react/components/root/RootProps.h>
|
|
#include <react/components/view/ConcreteViewShadowNode.h>
|
|
#include <react/core/LayoutContext.h>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
class RootShadowNode;
|
|
|
|
extern const char RootComponentName[];
|
|
|
|
/*
|
|
* `ShadowNode` for the root component.
|
|
* Besides all functionality of the `View` component, `RootShadowNode` contains
|
|
* props which represent external layout constraints and context of the
|
|
* shadow tree.
|
|
*/
|
|
class RootShadowNode final
|
|
: public ConcreteViewShadowNode<RootComponentName, RootProps> {
|
|
public:
|
|
using ConcreteViewShadowNode::ConcreteViewShadowNode;
|
|
|
|
using Shared = std::shared_ptr<RootShadowNode const>;
|
|
using Unshared = std::shared_ptr<RootShadowNode>;
|
|
|
|
/*
|
|
* Layouts the shadow tree.
|
|
*/
|
|
void layout(std::vector<LayoutableShadowNode const *> *affectedNodes = {});
|
|
|
|
/*
|
|
* Clones the node with given `layoutConstraints` and `layoutContext`.
|
|
*/
|
|
RootShadowNode::Unshared clone(
|
|
LayoutConstraints const &layoutConstraints,
|
|
LayoutContext const &layoutContext) const;
|
|
|
|
/*
|
|
* Clones the node replacing a given old shadow node with a new one in the
|
|
* tree by cloning all nodes on the path to the root node and then complete
|
|
* the tree. Returns `nullptr` if the operation cannot be finished
|
|
* successfully.
|
|
*/
|
|
RootShadowNode::Unshared clone(
|
|
ShadowNode const &oldShadowNode,
|
|
ShadowNode::Shared const &newShadowNode) const;
|
|
|
|
private:
|
|
using YogaLayoutableShadowNode::layout;
|
|
};
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|