Skip to content

Commit 2080fd8

Browse files
Nick Lefeverfacebook-github-bot
authored andcommitted
Split shadow node reference setter and update functionality (#50752)
Summary: Pull Request resolved: #50752 Storing the runtime reference for a shadow node and updating the runtime reference to point at a specific shadow node should be separated so that these actions can be done at different moments in time. We want to keep a reference to the runtime reference of a shadow node for all revisions cloned internally (not triggered by the React renderer, e.g. on layout or shadow node state updates). We also want to support updating that runtime reference to point at a specific shadow node revision, ideally the one that will end up being used to mount the host component. Changelog: [Internal] Reviewed By: rubennorte Differential Revision: D73038438 fbshipit-source-id: 68c3912cbb077d790dd8d2abe8291548b12c8231
1 parent ee21580 commit 2080fd8

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,14 +310,19 @@ void ShadowNode::setRuntimeShadowNodeReference(
310310
runtimeShadowNodeReference_ = runtimeShadowNodeReference;
311311
}
312312

313+
void ShadowNode::updateRuntimeShadowNodeReference(
314+
const Shared& destinationShadowNode) const {
315+
if (auto reference = runtimeShadowNodeReference_.lock()) {
316+
reference->shadowNode = destinationShadowNode;
317+
}
318+
}
319+
313320
void ShadowNode::transferRuntimeShadowNodeReference(
314321
const Shared& destinationShadowNode) const {
315322
destinationShadowNode->runtimeShadowNodeReference_ =
316323
runtimeShadowNodeReference_;
317324

318-
if (auto reference = runtimeShadowNodeReference_.lock()) {
319-
reference->shadowNode = destinationShadowNode;
320-
}
325+
updateRuntimeShadowNodeReference(destinationShadowNode);
321326
}
322327

323328
void ShadowNode::transferRuntimeShadowNodeReference(

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ class ShadowNode : public Sealable,
187187
void setRuntimeShadowNodeReference(const std::shared_ptr<ShadowNodeWrapper>&
188188
runtimeShadowNodeReference) const;
189189

190+
/*
191+
* Update the runtime reference to point to the provided shadow node.
192+
*/
193+
void updateRuntimeShadowNodeReference(
194+
const Shared& destinationShadowNode) const;
195+
190196
/*
191197
* Transfer the runtime reference to this `ShadowNode` to a new instance,
192198
* updating the reference to point to the new `ShadowNode` referencing it.

0 commit comments

Comments
 (0)