Fabric: Using EventBeatBasedExecutor to ensure threading during installing UIManager

Summary: This is the last step before making JSIUIManagerInstaller a direct dependency of UIManager (and making UIManager installation process completely seamless/platform-agnostic).

Reviewed By: mdvacca

Differential Revision: D9995781

fbshipit-source-id: 6f8c7177495b01ebaac1dbe330f49dce2e2a552c
This commit is contained in:
Valentin Shergin 2018-09-26 10:02:01 -07:00 коммит произвёл Facebook Github Bot
Родитель 78746afd92
Коммит b91f6d1e93
4 изменённых файлов: 29 добавлений и 8 удалений

Просмотреть файл

@ -9,6 +9,8 @@
#include "EventBeatBasedExecutor.h" #include "EventBeatBasedExecutor.h"
#include <cassert>
namespace facebook { namespace facebook {
namespace react { namespace react {

Просмотреть файл

@ -89,15 +89,24 @@ static const std::string componentNameByReactViewName(std::string viewName) {
return viewName; return viewName;
} }
FabricUIManager::FabricUIManager(std::function<UIManagerInstaller> installer, std::function<UIManagerUninstaller> uninstaller): FabricUIManager::FabricUIManager(
installer_(std::move(installer)), std::unique_ptr<EventBeatBasedExecutor> executor,
uninstaller_(std::move(uninstaller)) { std::function<UIManagerInstaller> installer,
std::function<UIManagerUninstaller> uninstaller
):
executor_(std::move(executor)),
installer_(std::move(installer)),
uninstaller_(std::move(uninstaller)) {
installer_(*this); (*executor_)([this] {
installer_(*this);
});
} }
FabricUIManager::~FabricUIManager() { FabricUIManager::~FabricUIManager() {
uninstaller_(); (*executor_)([this] {
uninstaller_();
}, EventBeatBasedExecutor::Mode::Synchronous);
} }
void FabricUIManager::setComponentDescriptorRegistry(const SharedComponentDescriptorRegistry &componentDescriptorRegistry) { void FabricUIManager::setComponentDescriptorRegistry(const SharedComponentDescriptorRegistry &componentDescriptorRegistry) {

Просмотреть файл

@ -12,6 +12,7 @@
#include <folly/dynamic.h> #include <folly/dynamic.h>
#include <fabric/core/ShadowNode.h> #include <fabric/core/ShadowNode.h>
#include <fabric/events/EventBeatBasedExecutor.h>
#include <fabric/uimanager/ComponentDescriptorRegistry.h> #include <fabric/uimanager/ComponentDescriptorRegistry.h>
#include <fabric/uimanager/UIManagerDelegate.h> #include <fabric/uimanager/UIManagerDelegate.h>
@ -34,7 +35,11 @@ using DispatchEventToTargetFunction = void (const EventHandler &eventHandler, co
class FabricUIManager { class FabricUIManager {
public: public:
FabricUIManager(std::function<UIManagerInstaller> installer, std::function<UIManagerUninstaller> uninstaller); FabricUIManager(
std::unique_ptr<EventBeatBasedExecutor> executor,
std::function<UIManagerInstaller> installer,
std::function<UIManagerUninstaller> uninstaller
);
~FabricUIManager(); ~FabricUIManager();
#pragma mark - Native-facing Interface #pragma mark - Native-facing Interface
@ -88,6 +93,7 @@ private:
std::function<DispatchEventToEmptyTargetFunction> dispatchEventToEmptyTargetFunction_; std::function<DispatchEventToEmptyTargetFunction> dispatchEventToEmptyTargetFunction_;
std::function<DispatchEventToTargetFunction> dispatchEventToTargetFunction_; std::function<DispatchEventToTargetFunction> dispatchEventToTargetFunction_;
std::unique_ptr<EventBeatBasedExecutor> executor_;
std::function<UIManagerInstaller> installer_; std::function<UIManagerInstaller> installer_;
std::function<UIManagerUninstaller> uninstaller_; std::function<UIManagerUninstaller> uninstaller_;
}; };

Просмотреть файл

@ -18,7 +18,11 @@ namespace react {
Scheduler::Scheduler(const SharedContextContainer &contextContainer): Scheduler::Scheduler(const SharedContextContainer &contextContainer):
contextContainer_(contextContainer) { contextContainer_(contextContainer) {
const auto asynchronousEventBeatFactory = contextContainer->getInstance<EventBeatFactory>("asynchronous");
const auto synchronousEventBeatFactory = contextContainer->getInstance<EventBeatFactory>("synchronous");
uiManager_ = std::make_shared<FabricUIManager>( uiManager_ = std::make_shared<FabricUIManager>(
std::make_unique<EventBeatBasedExecutor>(asynchronousEventBeatFactory()),
contextContainer->getInstance<std::function<UIManagerInstaller>>("uimanager-installer"), contextContainer->getInstance<std::function<UIManagerInstaller>>("uimanager-installer"),
contextContainer->getInstance<std::function<UIManagerUninstaller>>("uimanager-uninstaller") contextContainer->getInstance<std::function<UIManagerUninstaller>>("uimanager-uninstaller")
); );
@ -32,8 +36,8 @@ Scheduler::Scheduler(const SharedContextContainer &contextContainer):
std::placeholders::_2, std::placeholders::_2,
std::placeholders::_3 std::placeholders::_3
), ),
contextContainer->getInstance<EventBeatFactory>("synchronous"), synchronousEventBeatFactory,
contextContainer->getInstance<EventBeatFactory>("asynchronous") asynchronousEventBeatFactory
); );
uiManager_->setComponentDescriptorRegistry( uiManager_->setComponentDescriptorRegistry(