Skip to content

Commit 6ed06d7

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
deprecate type aliases ShadowNode::Unshared and ShadowNode::Weak
Summary: changelog: [General][Deprecated] - deprecate type aliases ShadowNode::Unshared and ShadowNode::Weak in favour of std::shared_ptr<ShadowNode> and std::weak_ptr<ShadowNode> migrate away from using these type aliases to avoid confusion. It is unclear from ShadowNode::Unshared what it means. This can be avoided by using std::shared_ptr<ShadowNode> directly. The same applies to ShadowNode::Weak. Reviewed By: rubennorte Differential Revision: D74245228
1 parent 12627f1 commit 6ed06d7

13 files changed

Lines changed: 38 additions & 32 deletions

File tree

packages/react-native/ReactCommon/react/renderer/components/text/ParagraphShadowNode.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ void ParagraphShadowNode::layout(LayoutContext layoutContext) {
313313
// `paragraphOwningShadowNode` is owning pointer to`paragraphShadowNode`
314314
// (besides the initial case when `paragraphShadowNode == this`), we need
315315
// this only to keep it in memory for a while.
316-
auto paragraphOwningShadowNode = ShadowNode::Unshared{};
316+
auto paragraphOwningShadowNode = std::shared_ptr<ShadowNode>{};
317317

318318
react_native_assert(
319319
content.attachments.size() == measurement.attachments.size());
@@ -327,7 +327,7 @@ void ParagraphShadowNode::layout(LayoutContext layoutContext) {
327327
continue;
328328
}
329329

330-
auto clonedShadowNode = ShadowNode::Unshared{};
330+
auto clonedShadowNode = std::shared_ptr<ShadowNode>{};
331331

332332
paragraphOwningShadowNode = paragraphShadowNode->cloneTree(
333333
attachment.shadowNode->getFamily(),

packages/react-native/ReactCommon/react/renderer/core/ComponentDescriptor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class ComponentDescriptor {
8585
/*
8686
* Clones a `ShadowNode` with optionally new `props` and/or `children`.
8787
*/
88-
virtual ShadowNode::Unshared cloneShadowNode(
88+
virtual std::shared_ptr<ShadowNode> cloneShadowNode(
8989
const ShadowNode& sourceShadowNode,
9090
const ShadowNodeFragment& fragment) const = 0;
9191

packages/react-native/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class ConcreteComponentDescriptor : public ComponentDescriptor {
7676
return shadowNode;
7777
}
7878

79-
ShadowNode::Unshared cloneShadowNode(
79+
std::shared_ptr<ShadowNode> cloneShadowNode(
8080
const ShadowNode& sourceShadowNode,
8181
const ShadowNodeFragment& fragment) const override {
8282
auto shadowNode = std::make_shared<ShadowNodeT>(sourceShadowNode, fragment);

packages/react-native/ReactCommon/react/renderer/core/ShadowNode.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ ShadowNode::ShadowNode(
133133
}
134134
}
135135

136-
ShadowNode::Unshared ShadowNode::clone(
136+
std::shared_ptr<ShadowNode> ShadowNode::clone(
137137
const ShadowNodeFragment& fragment) const {
138138
const auto& family = *family_;
139139
const auto& componentDescriptor = family.componentDescriptor_;
@@ -340,14 +340,14 @@ ShadowNodeFamily::Shared ShadowNode::getFamilyShared() const {
340340
return family_;
341341
}
342342

343-
ShadowNode::Unshared ShadowNode::cloneTree(
343+
std::shared_ptr<ShadowNode> ShadowNode::cloneTree(
344344
const ShadowNodeFamily& shadowNodeFamily,
345-
const std::function<ShadowNode::Unshared(const ShadowNode& oldShadowNode)>&
346-
callback) const {
345+
const std::function<std::shared_ptr<ShadowNode>(
346+
const ShadowNode& oldShadowNode)>& callback) const {
347347
auto ancestors = shadowNodeFamily.getAncestors(*this);
348348

349349
if (ancestors.empty()) {
350-
return ShadowNode::Unshared{nullptr};
350+
return std::shared_ptr<ShadowNode>{nullptr};
351351
}
352352

353353
auto& parent = ancestors.back();

packages/react-native/ReactCommon/react/renderer/core/ShadowNode.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ class ShadowNode : public Sealable,
3333
public jsi::NativeState {
3434
public:
3535
using Shared = std::shared_ptr<const ShadowNode>;
36-
using Weak = std::weak_ptr<const ShadowNode>;
37-
using Unshared = std::shared_ptr<ShadowNode>;
36+
// TODO(T223558094): delete this in the next version.
37+
using Weak [[deprecated("Use std::weak_ptr<const ShadowNode> instead")]] =
38+
std::weak_ptr<const ShadowNode>;
39+
// TODO(T223558094): delete this in the next version.
40+
using Unshared [[deprecated("Use std::weak_ptr<const ShadowNode> instead")]] =
41+
std::shared_ptr<ShadowNode>;
3842
using ListOfShared = std::vector<Shared>;
39-
using ListOfWeak = std::vector<Weak>;
43+
using ListOfWeak = std::vector<std::weak_ptr<const ShadowNode>>;
4044
using SharedListOfShared = std::shared_ptr<const ListOfShared>;
4145
using UnsharedListOfShared = std::shared_ptr<ListOfShared>;
4246
using UnsharedListOfWeak = std::shared_ptr<ListOfWeak>;
@@ -93,7 +97,7 @@ class ShadowNode : public Sealable,
9397
/*
9498
* Clones the shadow node using stored `cloneFunction`.
9599
*/
96-
Unshared clone(const ShadowNodeFragment& fragment) const;
100+
std::shared_ptr<ShadowNode> clone(const ShadowNodeFragment& fragment) const;
97101

98102
/*
99103
* Clones the node (and partially the tree starting from the node) by
@@ -102,10 +106,10 @@ class ShadowNode : public Sealable,
102106
*
103107
* Returns `nullptr` if the operation cannot be performed successfully.
104108
*/
105-
Unshared cloneTree(
109+
std::shared_ptr<ShadowNode> cloneTree(
106110
const ShadowNodeFamily& shadowNodeFamily,
107-
const std::function<Unshared(const ShadowNode& oldShadowNode)>& callback)
108-
const;
111+
const std::function<std::shared_ptr<ShadowNode>(
112+
const ShadowNode& oldShadowNode)>& callback) const;
109113

110114
#pragma mark - Getters
111115

packages/react-native/ReactCommon/react/renderer/element/ComponentBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ComponentBuilder::ComponentBuilder(
1515
ComponentDescriptorRegistry::Shared componentDescriptorRegistry)
1616
: componentDescriptorRegistry_(std::move(componentDescriptorRegistry)){};
1717

18-
ShadowNode::Unshared ComponentBuilder::build(
18+
std::shared_ptr<ShadowNode> ComponentBuilder::build(
1919
const ElementFragment& elementFragment) const {
2020
auto& componentDescriptor =
2121
componentDescriptorRegistry_->at(elementFragment.componentHandle);

packages/react-native/ReactCommon/react/renderer/element/ComponentBuilder.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ class ComponentBuilder final {
4848
/*
4949
* Internal, type-erased version of `build`.
5050
*/
51-
ShadowNode::Unshared build(const ElementFragment& elementFragment) const;
51+
std::shared_ptr<ShadowNode> build(
52+
const ElementFragment& elementFragment) const;
5253

5354
ComponentDescriptorRegistry::Shared componentDescriptorRegistry_;
5455
};

packages/react-native/ReactCommon/react/renderer/element/ElementFragment.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ElementFragment final {
2727
using List = std::vector<ElementFragment>;
2828
using ListOfShared = std::vector<Shared>;
2929
using ReferenceCallback =
30-
std::function<void(const ShadowNode::Unshared& shadowNode)>;
30+
std::function<void(const std::shared_ptr<ShadowNode>& shadowNode)>;
3131
using FinalizeCallback = std::function<void(ShadowNode& shadowNode)>;
3232
using StateCallback =
3333
std::function<StateData::Shared(const State::Shared& state)>;

packages/react-native/ReactCommon/react/renderer/mounting/ShadowTree.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ using CommitMode = ShadowTree::CommitMode;
3131
* of calling, the function returns `nullptr` (as an indication that no
3232
* additional work is required).
3333
*/
34-
static ShadowNode::Unshared progressState(const ShadowNode& shadowNode) {
34+
static std::shared_ptr<ShadowNode> progressState(const ShadowNode& shadowNode) {
3535
auto isStateChanged = false;
3636
auto areChildrenChanged = false;
3737

@@ -78,7 +78,7 @@ static ShadowNode::Unshared progressState(const ShadowNode& shadowNode) {
7878
* The function uses a given base tree to exclude unchanged (equal) parts
7979
* of the three from the traversing.
8080
*/
81-
static ShadowNode::Unshared progressState(
81+
static std::shared_ptr<ShadowNode> progressState(
8282
const ShadowNode& shadowNode,
8383
const ShadowNode& baseShadowNode) {
8484
// The intuition behind the complexity:
@@ -357,7 +357,8 @@ void ShadowTree::mount(ShadowTreeRevision revision, bool mountSynchronously)
357357

358358
void ShadowTree::commitEmptyTree() const {
359359
commit(
360-
[](const RootShadowNode& oldRootShadowNode) -> RootShadowNode::Unshared {
360+
[](const RootShadowNode& oldRootShadowNode)
361+
-> std::shared_ptr<RootShadowNode> {
361362
return std::make_shared<RootShadowNode>(
362363
oldRootShadowNode,
363364
ShadowNodeFragment{

packages/react-native/ReactCommon/react/renderer/scheduler/SurfaceHandler.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,7 @@ std::shared_ptr<const ShadowNode> SurfaceHandler::dirtyMeasurableNodesRecursive(
248248
ShadowNodeFragment::childrenPlaceholder();
249249

250250
if (nodeHasChildren) {
251-
ShadowNode::UnsharedListOfShared newChildrenMutable = nullptr;
252-
251+
std::shared_ptr<ShadowNode::ListOfShared> newChildrenMutable = nullptr;
253252
for (size_t i = 0; i < node->getChildren().size(); i++) {
254253
const auto& child = node->getChildren()[i];
255254

0 commit comments

Comments
 (0)