From 3dd92513c55032c201111cfbb4efce4484eda605 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Tue, 23 Mar 2021 13:39:21 -0700 Subject: [PATCH] Fabric: Aligning `UIManager::startSurface` and `UIManager::stopSurface` signatures Summary: In the previous diff, we moved the destruction of a ShadowTree object from `UIManager::stopSurface` method. And the next logical step is to align `UIManager::startSurface` method with the symmetrical approach. Now `stopSurface` accepts a unique pointer to a ShadowTree and `stopSurface` returns it back to the caller; this way we can avoid returning a raw pointer from `startSurface`. Changelog: [Internal] Fabric-specific internal change. Reviewed By: sammy-SC Differential Revision: D27010533 fbshipit-source-id: b9211fb7e67763cc190d6b8c86cb866d20c6693d --- .../react/renderer/scheduler/SurfaceHandler.cpp | 12 ++++++++---- ReactCommon/react/renderer/uimanager/UIManager.cpp | 14 ++++---------- ReactCommon/react/renderer/uimanager/UIManager.h | 8 +++----- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/ReactCommon/react/renderer/scheduler/SurfaceHandler.cpp b/ReactCommon/react/renderer/scheduler/SurfaceHandler.cpp index fead649c5ed..e022b69309e 100644 --- a/ReactCommon/react/renderer/scheduler/SurfaceHandler.cpp +++ b/ReactCommon/react/renderer/scheduler/SurfaceHandler.cpp @@ -68,12 +68,16 @@ void SurfaceHandler::start() const noexcept { parameters = parameters_; } - link_.shadowTree = &link_.uiManager->startSurface( + auto shadowTree = std::make_unique( parameters.surfaceId, - parameters.moduleName, - parameters.props, parameters.layoutConstraints, - parameters.layoutContext); + parameters.layoutContext, + *link_.uiManager); + + link_.shadowTree = shadowTree.get(); + + link_.uiManager->startSurface( + std::move(shadowTree), parameters.moduleName, parameters.props); link_.status = Status::Running; diff --git a/ReactCommon/react/renderer/uimanager/UIManager.cpp b/ReactCommon/react/renderer/uimanager/UIManager.cpp index 1ede96f843c..5a8044b6ee1 100644 --- a/ReactCommon/react/renderer/uimanager/UIManager.cpp +++ b/ReactCommon/react/renderer/uimanager/UIManager.cpp @@ -146,17 +146,13 @@ void UIManager::setIsJSResponder( } } -ShadowTree const &UIManager::startSurface( - SurfaceId surfaceId, +void UIManager::startSurface( + ShadowTree::Unique &&shadowTree, std::string const &moduleName, - folly::dynamic const &props, - LayoutConstraints const &layoutConstraints, - LayoutContext const &layoutContext) const { + folly::dynamic const &props) const { SystraceSection s("UIManager::startSurface"); - auto shadowTree = std::make_unique( - surfaceId, layoutConstraints, layoutContext, *this); - auto shadowTreePointer = shadowTree.get(); + auto surfaceId = shadowTree->getSurfaceId(); shadowTreeRegistry_.add(std::move(shadowTree)); runtimeExecutor_([=](jsi::Runtime &runtime) { @@ -167,8 +163,6 @@ ShadowTree const &UIManager::startSurface( uiManagerBinding->startSurface(runtime, surfaceId, moduleName, props); }); - - return *shadowTreePointer; } ShadowTree::Unique UIManager::stopSurface(SurfaceId surfaceId) const { diff --git a/ReactCommon/react/renderer/uimanager/UIManager.h b/ReactCommon/react/renderer/uimanager/UIManager.h index 723b7a23a6d..a6fa5b7db88 100644 --- a/ReactCommon/react/renderer/uimanager/UIManager.h +++ b/ReactCommon/react/renderer/uimanager/UIManager.h @@ -85,12 +85,10 @@ class UIManager final : public ShadowTreeDelegate { #pragma mark - Surface Start & Stop - ShadowTree const &startSurface( - SurfaceId surfaceId, + void startSurface( + ShadowTree::Unique &&shadowTree, std::string const &moduleName, - folly::dynamic const &props, - LayoutConstraints const &layoutConstraints, - LayoutContext const &layoutContext) const; + folly::dynamic const &props) const; ShadowTree::Unique stopSurface(SurfaceId surfaceId) const;