Skip to content

Commit afa4b1d

Browse files
committed
feat: add new hook shadowTreeDidCommit
1 parent 3958c7f commit afa4b1d

5 files changed

Lines changed: 46 additions & 0 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,9 @@ CommitStatus ShadowTree::tryCommit(
463463
}
464464
}
465465

466+
delegate_.shadowTreeDidCommit(
467+
*this, newRevision.rootShadowNode, affectedLayoutableNodes);
468+
466469
emitLayoutEvents(affectedLayoutableNodes);
467470

468471
if (isReactBranch) {

packages/react-native/ReactCommon/react/renderer/mounting/ShadowTreeDelegate.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace facebook::react {
1313

14+
class LayoutableShadowNode;
1415
class ShadowTree;
1516
struct ShadowTreeCommitOptions;
1617

@@ -49,6 +50,16 @@ class ShadowTreeDelegate {
4950
*/
5051
virtual void shadowTreeDidPromoteReactRevision(const ShadowTree &shadowTree) const = 0;
5152

53+
/*
54+
* Called right after a Shadow Tree commits a new tree, reporting the nodes
55+
* whose layout changed in this commit.
56+
*/
57+
virtual void shadowTreeDidCommit(
58+
const ShadowTree& shadowTree,
59+
const RootShadowNode::Shared& rootShadowNode,
60+
const std::vector<const LayoutableShadowNode*>& affectedLayoutableNodes)
61+
const noexcept {}
62+
5263
virtual ~ShadowTreeDelegate() noexcept = default;
5364
};
5465

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,21 @@ void UIManager::shadowTreeDidPromoteReactRevision(
670670
}
671671
}
672672

673+
void UIManager::shadowTreeDidCommit(
674+
const ShadowTree& shadowTree,
675+
const RootShadowNode::Shared& rootShadowNode,
676+
const std::vector<const LayoutableShadowNode*>& affectedLayoutableNodes)
677+
const noexcept {
678+
TraceSection s("UIManager::shadowTreeDidCommit");
679+
680+
std::shared_lock lock(commitHookMutex_);
681+
682+
for (auto* commitHook : commitHooks_) {
683+
commitHook->shadowTreeDidCommit(
684+
shadowTree, rootShadowNode, affectedLayoutableNodes);
685+
}
686+
}
687+
673688
void UIManager::reportMount(SurfaceId surfaceId) const {
674689
TraceSection s("UIManager::reportMount");
675690

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ class UIManager final : public ShadowTreeDelegate {
146146

147147
void shadowTreeDidPromoteReactRevision(const ShadowTree &shadowTree) const override;
148148

149+
void shadowTreeDidCommit(
150+
const ShadowTree& shadowTree,
151+
const RootShadowNode::Shared& rootShadowNode,
152+
const std::vector<const LayoutableShadowNode*>& affectedLayoutableNodes)
153+
const noexcept override;
154+
149155
std::shared_ptr<ShadowNode> createNode(
150156
Tag tag,
151157
const std::string &componentName,

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace facebook::react {
1313

14+
class LayoutableShadowNode;
1415
class ShadowTree;
1516
struct ShadowTreeCommitOptions;
1617
class UIManager;
@@ -54,6 +55,16 @@ class UIManagerCommitHook {
5455
return newRootShadowNode;
5556
}
5657

58+
/*
59+
* Called right after a `ShadowTree` commits a new tree.
60+
* The semantic of the method corresponds to a method of the same name
61+
* from `ShadowTreeDelegate`.
62+
*/
63+
virtual void shadowTreeDidCommit(
64+
const ShadowTree& /*shadowTree*/,
65+
const RootShadowNode::Shared& /*rootShadowNode*/,
66+
const std::vector<const LayoutableShadowNode*>& /*affectedLayoutableNodes*/) noexcept {}
67+
5768
virtual ~UIManagerCommitHook() noexcept = default;
5869
};
5970

0 commit comments

Comments
 (0)