mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Fabric: Clarifying life-time concerns of ShadowTree::delegate_
Summary: This diff makes it clear from the code that ShadowTree delegate must be around for the whole life-time of a ShadowTree instance and there is no way to revoke/reset the delegate. This makes reasoning about the lifetime much simpler. We didn't call `setDelegate(nullptr)` before, so nothing really changes here. Changelog: [Internal] Fabric-specific internal change. Reviewed By: mdvacca Differential Revision: D18542502 fbshipit-source-id: f57ee21e0bb533fb82cb6f8ba7723e40ffb25a38
This commit is contained in:
1 parent
b346970016
commit
9349ee26e7
3 files changed
+14
-31
No files matched your search
@@ -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<const ViewEventEmitter>(
|
||||
nullptr, -1, std::shared_ptr<const EventDispatcher>());
|
||||
|
||||
@@ -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
|
||||
@@ -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<LayoutableShadowNode const *> &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_;
|
||||
};
|
||||
|
||||
|
||||
@@ -134,8 +134,11 @@ void Scheduler::startSurface(
|
||||
SystraceSection s("Scheduler::startSurface");
|
||||
|
||||
auto shadowTree = std::make_unique<ShadowTree>(
|
||||
surfaceId, layoutConstraints, layoutContext, *rootComponentDescriptor_);
|
||||
shadowTree->setDelegate(uiManager_.get());
|
||||
surfaceId,
|
||||
layoutConstraints,
|
||||
layoutContext,
|
||||
*rootComponentDescriptor_,
|
||||
*uiManager_);
|
||||
|
||||
auto uiManager = uiManager_;
|
||||
|
||||
|
||||
Reference in new issue
Block a user