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 committed by Facebook Github Bot
parent 78746afd92
commit b91f6d1e93
4 changed files with 29 additions and 8 deletions

View File

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

View File

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

View File

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

View File

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