From 961b6aceca22753c061af2bf885317ac28a22a90 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Mon, 27 Aug 2018 07:21:26 -0700 Subject: [PATCH] Fabric: Unified event pipeline: connecting the dots Summary: @public This diff basically wires everything up. Reviewed By: mdvacca Differential Revision: D8886227 fbshipit-source-id: fb1a1e3222b3d693a8c28ed780b14f7315b7c019 --- React/Fabric/RCTScheduler.mm | 24 +++++++++++++++++ .../fabric/uimanager/FabricUIManager.cpp | 8 +++--- .../fabric/uimanager/FabricUIManager.h | 3 ++- ReactCommon/fabric/uimanager/Scheduler.cpp | 26 ++++++++++++++----- ReactCommon/fabric/uimanager/Scheduler.h | 2 +- 5 files changed, 50 insertions(+), 13 deletions(-) diff --git a/React/Fabric/RCTScheduler.mm b/React/Fabric/RCTScheduler.mm index 3f441b1c2..3e1d89236 100644 --- a/React/Fabric/RCTScheduler.mm +++ b/React/Fabric/RCTScheduler.mm @@ -14,8 +14,16 @@ #import #import +#import "MainRunLoopEventBeat.h" +#import "MessageQueueEventBeat.h" #import "RCTConversions.h" +@interface RCTBridge () + +- (std::shared_ptr)jsMessageThread; + +@end + using namespace facebook::react; class SchedulerDelegateProxy: public SchedulerDelegate { @@ -46,8 +54,24 @@ private: if (self = [super init]) { _delegateProxy = std::make_shared((__bridge void *)self); + RCTBridge *bridge = [RCTBridge currentBridge]; + SharedContextContainer contextContainer = std::make_shared(); + EventBeatFactory synchronousBeatFactory = []() { + return std::make_unique(); + }; + + EventBeatFactory asynchronousBeatFactory = [bridge]() { + return std::make_unique(bridge.jsMessageThread); + }; + + contextContainer->registerInstance(synchronousBeatFactory, "synchronous"); + contextContainer->registerInstance(asynchronousBeatFactory, "asynchronous"); + + contextContainer->registerInstance>(std::make_shared(), "synchronous"); + contextContainer->registerInstance>(std::make_shared(bridge.jsMessageThread), "asynchronous"); + void *imageLoader = (__bridge void *)[[RCTBridge currentBridge] imageLoader]; contextContainer->registerInstance(std::make_shared(imageLoader)); diff --git a/ReactCommon/fabric/uimanager/FabricUIManager.cpp b/ReactCommon/fabric/uimanager/FabricUIManager.cpp index 62499d4ae..496ca45d3 100644 --- a/ReactCommon/fabric/uimanager/FabricUIManager.cpp +++ b/ReactCommon/fabric/uimanager/FabricUIManager.cpp @@ -80,16 +80,16 @@ static const std::string componentNameByReactViewName(std::string viewName) { return viewName; } -FabricUIManager::FabricUIManager(SharedComponentDescriptorRegistry componentDescriptorRegistry) { - componentDescriptorRegistry_ = componentDescriptorRegistry; -} - FabricUIManager::~FabricUIManager() { if (eventHandler_) { releaseEventHandlerFunction_(eventHandler_); } } +void FabricUIManager::setComponentDescriptorRegistry(const SharedComponentDescriptorRegistry &componentDescriptorRegistry) { + componentDescriptorRegistry_ = componentDescriptorRegistry; +} + void FabricUIManager::setDelegate(UIManagerDelegate *delegate) { delegate_ = delegate; } diff --git a/ReactCommon/fabric/uimanager/FabricUIManager.h b/ReactCommon/fabric/uimanager/FabricUIManager.h index 8bb0eff72..50a84cf8b 100644 --- a/ReactCommon/fabric/uimanager/FabricUIManager.h +++ b/ReactCommon/fabric/uimanager/FabricUIManager.h @@ -28,9 +28,10 @@ public: #pragma mark - Native-facing Interface - FabricUIManager(SharedComponentDescriptorRegistry componentDescriptorRegistry); ~FabricUIManager(); + void setComponentDescriptorRegistry(const SharedComponentDescriptorRegistry &componentDescriptorRegistry); + /* * Sets and gets the UIManager's delegate. * The delegate is stored as a raw pointer, so the owner must null diff --git a/ReactCommon/fabric/uimanager/Scheduler.cpp b/ReactCommon/fabric/uimanager/Scheduler.cpp index 08b1980bb..d338edc9f 100644 --- a/ReactCommon/fabric/uimanager/Scheduler.cpp +++ b/ReactCommon/fabric/uimanager/Scheduler.cpp @@ -17,19 +17,31 @@ namespace react { Scheduler::Scheduler(const SharedContextContainer &contextContainer): contextContainer_(contextContainer) { - const auto &eventDispatcher = std::make_shared(); - const auto &componentDescriptorRegistry = ComponentDescriptorFactory::buildRegistry(eventDispatcher, contextContainer); - uiManager_ = std::make_shared(componentDescriptorRegistry); + uiManager_ = std::make_shared(); + + auto eventDispatcher = + std::make_shared( + std::bind( + &FabricUIManager::dispatchEventToTarget, + uiManager_.get(), + std::placeholders::_1, + std::placeholders::_2, + std::placeholders::_3 + ), + contextContainer->getInstance("synchronous"), + contextContainer->getInstance("asynchronous") + ); + + uiManager_->setComponentDescriptorRegistry( + ComponentDescriptorFactory::buildRegistry(eventDispatcher, contextContainer) + ); + uiManager_->setDelegate(this); - - eventDispatcher->setUIManager(uiManager_); - eventDispatcher_ = eventDispatcher; } Scheduler::~Scheduler() { uiManager_->setDelegate(nullptr); - eventDispatcher_->setUIManager(nullptr); } void Scheduler::registerRootTag(Tag rootTag) { diff --git a/ReactCommon/fabric/uimanager/Scheduler.h b/ReactCommon/fabric/uimanager/Scheduler.h index ce7ccfa41..22f15349a 100644 --- a/ReactCommon/fabric/uimanager/Scheduler.h +++ b/ReactCommon/fabric/uimanager/Scheduler.h @@ -71,7 +71,7 @@ private: SchedulerDelegate *delegate_; std::shared_ptr uiManager_; std::unordered_map shadowTreeRegistry_; - SharedSchedulerEventDispatcher eventDispatcher_; + SharedEventDispatcher eventDispatcher_; SharedContextContainer contextContainer_; };