Skip to content

Commit 9cff12c

Browse files
sammy-SCmeta-codesync[bot]
authored andcommitted
Deprecate and replace obscure ShadowNode type aliases (#55690)
Summary: Pull Request resolved: #55690 Changelog: [internal] Mark these obscure type aliases as deprecated and replace all usages with explicit types: - `ShadowNode::SharedListOfShared` → `std::shared_ptr<const std::vector<std::shared_ptr<const ShadowNode>>>` - `ShadowNode::UnsharedListOfShared` → `std::shared_ptr<std::vector<std::shared_ptr<const ShadowNode>>>` - `ShadowNode::UnsharedListOfWeak` → `std::shared_ptr<std::vector<std::weak_ptr<const ShadowNode>>>` the type aliases will be deleted later. Reviewed By: lenaic Differential Revision: D90331677 fbshipit-source-id: 1323766a9e725e75e3a45c14c259cd3a61f11388
1 parent 796a9a8 commit 9cff12c

8 files changed

Lines changed: 45 additions & 24 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ thread_local bool useRuntimeShadowNodeReferenceUpdateOnThread{false}; // NOLINT
3636
return useRuntimeShadowNodeReferenceUpdateOnThread;
3737
}
3838

39-
ShadowNode::SharedListOfShared ShadowNode::emptySharedShadowNodeSharedList() {
39+
std::shared_ptr<const std::vector<std::shared_ptr<const ShadowNode>>>
40+
ShadowNode::emptySharedShadowNodeSharedList() {
4041
static const auto emptySharedShadowNodeSharedList =
4142
std::make_shared<std::vector<std::shared_ptr<const ShadowNode>>>();
4243
return emptySharedShadowNodeSharedList;

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,19 @@ struct ShadowNodeWrapper;
3030

3131
class ShadowNode : public Sealable, public DebugStringConvertible, public jsi::NativeState {
3232
public:
33-
using SharedListOfShared = std::shared_ptr<const std::vector<std::shared_ptr<const ShadowNode>>>;
34-
using UnsharedListOfShared = std::shared_ptr<std::vector<std::shared_ptr<const ShadowNode>>>;
35-
using UnsharedListOfWeak = std::shared_ptr<std::vector<std::weak_ptr<const ShadowNode>>>;
33+
using SharedListOfShared
34+
[[deprecated("Use std::shared_ptr<const std::vector<std::shared_ptr<const ShadowNode>>> instead")]] =
35+
std::shared_ptr<const std::vector<std::shared_ptr<const ShadowNode>>>;
36+
using UnsharedListOfShared
37+
[[deprecated("Use std::shared_ptr<std::vector<std::shared_ptr<const ShadowNode>>> instead")]] =
38+
std::shared_ptr<std::vector<std::shared_ptr<const ShadowNode>>>;
39+
using UnsharedListOfWeak [[deprecated("Use std::shared_ptr<std::vector<std::weak_ptr<const ShadowNode>>> instead")]] =
40+
std::shared_ptr<std::vector<std::weak_ptr<const ShadowNode>>>;
3641

3742
using AncestorList =
3843
std::vector<std::pair<std::reference_wrapper<const ShadowNode> /* parentNode */, int /* childIndex */>>;
3944

40-
static SharedListOfShared emptySharedShadowNodeSharedList();
45+
static std::shared_ptr<const std::vector<std::shared_ptr<const ShadowNode>>> emptySharedShadowNodeSharedList();
4146

4247
/*
4348
* Returns `true` if nodes belong to the same family (they were cloned one
@@ -226,7 +231,7 @@ class ShadowNode : public Sealable, public DebugStringConvertible, public jsi::N
226231

227232
protected:
228233
Props::Shared props_;
229-
SharedListOfShared children_;
234+
std::shared_ptr<const std::vector<std::shared_ptr<const ShadowNode>>> children_;
230235
State::Shared state_;
231236
int orderIndex_;
232237

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ const Props::Shared& ShadowNodeFragment::propsPlaceholder() {
2020
return instance;
2121
}
2222

23-
const ShadowNode::SharedListOfShared&
23+
const std::shared_ptr<const std::vector<std::shared_ptr<const ShadowNode>>>&
2424
ShadowNodeFragment::childrenPlaceholder() {
25-
NO_DESTROY static ShadowNode::SharedListOfShared instance;
25+
NO_DESTROY static std::shared_ptr<
26+
const std::vector<std::shared_ptr<const ShadowNode>>>
27+
instance;
2628
return instance;
2729
}
2830

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace facebook::react {
2424
*/
2525
struct ShadowNodeFragment {
2626
const Props::Shared &props = propsPlaceholder();
27-
const ShadowNode::SharedListOfShared &children = childrenPlaceholder();
27+
const std::shared_ptr<const std::vector<std::shared_ptr<const ShadowNode>>> &children = childrenPlaceholder();
2828
const State::Shared &state = statePlaceholder();
2929
const bool runtimeShadowNodeReference = true;
3030

@@ -34,7 +34,7 @@ struct ShadowNodeFragment {
3434
* be changed.
3535
*/
3636
static const Props::Shared &propsPlaceholder();
37-
static const ShadowNode::SharedListOfShared &childrenPlaceholder();
37+
static const std::shared_ptr<const std::vector<std::shared_ptr<const ShadowNode>>> &childrenPlaceholder();
3838
static const State::Shared &statePlaceholder();
3939
};
4040

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ std::shared_ptr<const ShadowNode> SurfaceHandler::dirtyMeasurableNodesRecursive(
224224
return nullptr;
225225
}
226226

227-
ShadowNode::SharedListOfShared newChildren =
228-
ShadowNodeFragment::childrenPlaceholder();
227+
std::shared_ptr<const std::vector<std::shared_ptr<const ShadowNode>>>
228+
newChildren = ShadowNodeFragment::childrenPlaceholder();
229229

230230
if (nodeHasChildren) {
231231
std::shared_ptr<std::vector<std::shared_ptr<const ShadowNode>>>

packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ std::shared_ptr<ShadowNode> UIManager::createNode(
107107

108108
std::shared_ptr<ShadowNode> UIManager::cloneNode(
109109
const ShadowNode& shadowNode,
110-
const ShadowNode::SharedListOfShared& children,
110+
const std::shared_ptr<const std::vector<std::shared_ptr<const ShadowNode>>>&
111+
children,
111112
RawProps rawProps) const {
112113
TraceSection s(
113114
"UIManager::cloneNode", "componentName", shadowNode.getComponentName());
@@ -184,7 +185,8 @@ void UIManager::appendChild(
184185

185186
void UIManager::completeSurface(
186187
SurfaceId surfaceId,
187-
const ShadowNode::UnsharedListOfShared& rootChildren,
188+
const std::shared_ptr<std::vector<std::shared_ptr<const ShadowNode>>>&
189+
rootChildren,
188190
ShadowTree::CommitOptions commitOptions) {
189191
TraceSection s("UIManager::completeSurface", "surfaceId", surfaceId);
190192

packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,18 @@ class UIManager final : public ShadowTreeDelegate {
146146
RawProps props,
147147
InstanceHandle::Shared instanceHandle) const;
148148

149-
std::shared_ptr<ShadowNode>
150-
cloneNode(const ShadowNode &shadowNode, const ShadowNode::SharedListOfShared &children, RawProps rawProps) const;
149+
std::shared_ptr<ShadowNode> cloneNode(
150+
const ShadowNode &shadowNode,
151+
const std::shared_ptr<const std::vector<std::shared_ptr<const ShadowNode>>> &children,
152+
RawProps rawProps) const;
151153

152154
void appendChild(
153155
const std::shared_ptr<const ShadowNode> &parentShadowNode,
154156
const std::shared_ptr<const ShadowNode> &childShadowNode) const;
155157

156158
void completeSurface(
157159
SurfaceId surfaceId,
158-
const ShadowNode::UnsharedListOfShared &rootChildren,
160+
const std::shared_ptr<std::vector<std::shared_ptr<const ShadowNode>>> &rootChildren,
159161
ShadowTree::CommitOptions commitOptions);
160162

161163
void setIsJSResponder(

packages/react-native/ReactCommon/react/renderer/uimanager/primitives.h

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@ namespace facebook::react {
1919
using BackgroundExecutor = std::function<void(std::function<void()> &&callback)>;
2020

2121
struct ShadowNodeListWrapper : public jsi::NativeState {
22-
ShadowNodeListWrapper(ShadowNode::UnsharedListOfShared shadowNodeList) : shadowNodeList(std::move(shadowNodeList)) {}
22+
ShadowNodeListWrapper(std::shared_ptr<std::vector<std::shared_ptr<const ShadowNode>>> shadowNodeList)
23+
: shadowNodeList(std::move(shadowNodeList))
24+
{
25+
}
2326

2427
// The below method needs to be implemented out-of-line in order for the class
2528
// to have at least one "key function" (see
2629
// https://itanium-cxx-abi.github.io/cxx-abi/abi.html#vague-vtable)
2730
~ShadowNodeListWrapper() override;
2831

29-
ShadowNode::UnsharedListOfShared shadowNodeList;
32+
std::shared_ptr<std::vector<std::shared_ptr<const ShadowNode>>> shadowNodeList;
3033
};
3134

3235
inline static jsi::Value valueFromShadowNode(
@@ -48,7 +51,9 @@ inline static jsi::Value valueFromShadowNode(
4851

4952
// TODO: once we no longer need to mutate the return value (appendChildToSet)
5053
// make this a SharedListOfShared
51-
inline static ShadowNode::UnsharedListOfShared shadowNodeListFromValue(jsi::Runtime &runtime, const jsi::Value &value)
54+
inline static std::shared_ptr<std::vector<std::shared_ptr<const ShadowNode>>> shadowNodeListFromValue(
55+
jsi::Runtime &runtime,
56+
const jsi::Value &value)
5257
{
5358
// TODO: cleanup when passChildrenWhenCloningPersistedNodes is rolled out
5459
jsi::Object object = value.asObject(runtime);
@@ -75,7 +80,9 @@ inline static ShadowNode::UnsharedListOfShared shadowNodeListFromValue(jsi::Runt
7580
}
7681
}
7782

78-
inline static jsi::Value valueFromShadowNodeList(jsi::Runtime &runtime, ShadowNode::UnsharedListOfShared shadowNodeList)
83+
inline static jsi::Value valueFromShadowNodeList(
84+
jsi::Runtime &runtime,
85+
std::shared_ptr<std::vector<std::shared_ptr<const ShadowNode>>> shadowNodeList)
7986
{
8087
auto wrapper = std::make_shared<ShadowNodeListWrapper>(std::move(shadowNodeList));
8188
// Use the wrapper for NativeState too, otherwise we can't implement
@@ -85,8 +92,8 @@ inline static jsi::Value valueFromShadowNodeList(jsi::Runtime &runtime, ShadowNo
8592
return obj;
8693
}
8794

88-
inline static ShadowNode::UnsharedListOfShared shadowNodeListFromWeakList(
89-
const ShadowNode::UnsharedListOfWeak &weakShadowNodeList)
95+
inline static std::shared_ptr<std::vector<std::shared_ptr<const ShadowNode>>> shadowNodeListFromWeakList(
96+
const std::shared_ptr<std::vector<std::weak_ptr<const ShadowNode>>> &weakShadowNodeList)
9097
{
9198
auto result = std::make_shared<std::vector<std::shared_ptr<const ShadowNode>>>();
9299
for (const auto &weakShadowNode : *weakShadowNodeList) {
@@ -99,7 +106,9 @@ inline static ShadowNode::UnsharedListOfShared shadowNodeListFromWeakList(
99106
return result;
100107
}
101108

102-
inline static ShadowNode::UnsharedListOfWeak weakShadowNodeListFromValue(jsi::Runtime &runtime, const jsi::Value &value)
109+
inline static std::shared_ptr<std::vector<std::weak_ptr<const ShadowNode>>> weakShadowNodeListFromValue(
110+
jsi::Runtime &runtime,
111+
const jsi::Value &value)
103112
{
104113
auto shadowNodeList = shadowNodeListFromValue(runtime, value);
105114
auto weakShadowNodeList = std::make_shared<std::vector<std::weak_ptr<const ShadowNode>>>();

0 commit comments

Comments
 (0)