diff --git a/ReactCommon/fabric/mounting/ShadowTree.cpp b/ReactCommon/fabric/mounting/ShadowTree.cpp index ce1689d7a87..72bb0313b50 100644 --- a/ReactCommon/fabric/mounting/ShadowTree.cpp +++ b/ReactCommon/fabric/mounting/ShadowTree.cpp @@ -91,10 +91,11 @@ static void updateMountedFlag( ShadowTree::ShadowTree( SurfaceId surfaceId, - const LayoutConstraints &layoutConstraints, - const LayoutContext &layoutContext, - const RootComponentDescriptor &rootComponentDescriptor) - : surfaceId_(surfaceId) { + LayoutConstraints const &layoutConstraints, + LayoutContext const &layoutContext, + RootComponentDescriptor const &rootComponentDescriptor, + ShadowTreeDelegate const &delegate) + : surfaceId_(surfaceId), delegate_(delegate) { const auto noopEventEmitter = std::make_shared( nullptr, -1, std::shared_ptr()); @@ -197,9 +198,7 @@ bool ShadowTree::tryCommit(ShadowTreeCommitTransaction transaction) const { mountingCoordinator_->push( ShadowTreeRevision{newRootShadowNode, revisionNumber, telemetry}); - if (delegate_) { - delegate_->shadowTreeDidFinishTransaction(*this, mountingCoordinator_); - } + delegate_.shadowTreeDidFinishTransaction(*this, mountingCoordinator_); return true; } @@ -244,15 +243,5 @@ void ShadowTree::emitLayoutEvents( } } -#pragma mark - Delegate - -void ShadowTree::setDelegate(ShadowTreeDelegate const *delegate) { - delegate_ = delegate; -} - -ShadowTreeDelegate const *ShadowTree::getDelegate() const { - return delegate_; -} - } // namespace react } // namespace facebook diff --git a/ReactCommon/fabric/mounting/ShadowTree.h b/ReactCommon/fabric/mounting/ShadowTree.h index 95dc67ac1ff..4653bebefaa 100644 --- a/ReactCommon/fabric/mounting/ShadowTree.h +++ b/ReactCommon/fabric/mounting/ShadowTree.h @@ -38,7 +38,8 @@ class ShadowTree final { SurfaceId surfaceId, LayoutConstraints const &layoutConstraints, LayoutContext const &layoutContext, - RootComponentDescriptor const &rootComponentDescriptor); + RootComponentDescriptor const &rootComponentDescriptor, + ShadowTreeDelegate const &delegate); ~ShadowTree(); @@ -65,16 +66,6 @@ class ShadowTree final { */ void commitEmptyTree() const; -#pragma mark - Delegate - - /* - * Sets and gets the delegate. - * The delegate is stored as a raw pointer, so the owner must null - * the pointer before being destroyed. - */ - void setDelegate(ShadowTreeDelegate const *delegate); - ShadowTreeDelegate const *getDelegate() const; - private: RootShadowNode::Unshared cloneRootShadowNode( RootShadowNode::Shared const &oldRootShadowNode, @@ -85,12 +76,12 @@ class ShadowTree final { std::vector &affectedLayoutableNodes) const; SurfaceId const surfaceId_; + ShadowTreeDelegate const &delegate_; mutable better::shared_mutex commitMutex_; mutable RootShadowNode::Shared rootShadowNode_; // Protected by `commitMutex_`. mutable ShadowTreeRevision::Number revisionNumber_{ 0}; // Protected by `commitMutex_`. - ShadowTreeDelegate const *delegate_; MountingCoordinator::Shared mountingCoordinator_; }; diff --git a/ReactCommon/fabric/uimanager/Scheduler.cpp b/ReactCommon/fabric/uimanager/Scheduler.cpp index f84e292df04..bcf88f10074 100644 --- a/ReactCommon/fabric/uimanager/Scheduler.cpp +++ b/ReactCommon/fabric/uimanager/Scheduler.cpp @@ -134,8 +134,11 @@ void Scheduler::startSurface( SystraceSection s("Scheduler::startSurface"); auto shadowTree = std::make_unique( - surfaceId, layoutConstraints, layoutContext, *rootComponentDescriptor_); - shadowTree->setDelegate(uiManager_.get()); + surfaceId, + layoutConstraints, + layoutContext, + *rootComponentDescriptor_, + *uiManager_); auto uiManager = uiManager_;