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
This commit is contained in:
parent
b49c8add15
commit
961b6aceca
|
@ -14,8 +14,16 @@
|
||||||
#import <React/RCTImageLoader.h>
|
#import <React/RCTImageLoader.h>
|
||||||
#import <React/RCTBridge+Private.h>
|
#import <React/RCTBridge+Private.h>
|
||||||
|
|
||||||
|
#import "MainRunLoopEventBeat.h"
|
||||||
|
#import "MessageQueueEventBeat.h"
|
||||||
#import "RCTConversions.h"
|
#import "RCTConversions.h"
|
||||||
|
|
||||||
|
@interface RCTBridge ()
|
||||||
|
|
||||||
|
- (std::shared_ptr<facebook::react::MessageQueueThread>)jsMessageThread;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
using namespace facebook::react;
|
using namespace facebook::react;
|
||||||
|
|
||||||
class SchedulerDelegateProxy: public SchedulerDelegate {
|
class SchedulerDelegateProxy: public SchedulerDelegate {
|
||||||
|
@ -46,8 +54,24 @@ private:
|
||||||
if (self = [super init]) {
|
if (self = [super init]) {
|
||||||
_delegateProxy = std::make_shared<SchedulerDelegateProxy>((__bridge void *)self);
|
_delegateProxy = std::make_shared<SchedulerDelegateProxy>((__bridge void *)self);
|
||||||
|
|
||||||
|
RCTBridge *bridge = [RCTBridge currentBridge];
|
||||||
|
|
||||||
SharedContextContainer contextContainer = std::make_shared<ContextContainer>();
|
SharedContextContainer contextContainer = std::make_shared<ContextContainer>();
|
||||||
|
|
||||||
|
EventBeatFactory synchronousBeatFactory = []() {
|
||||||
|
return std::make_unique<MainRunLoopEventBeat>();
|
||||||
|
};
|
||||||
|
|
||||||
|
EventBeatFactory asynchronousBeatFactory = [bridge]() {
|
||||||
|
return std::make_unique<MessageQueueEventBeat>(bridge.jsMessageThread);
|
||||||
|
};
|
||||||
|
|
||||||
|
contextContainer->registerInstance<EventBeatFactory>(synchronousBeatFactory, "synchronous");
|
||||||
|
contextContainer->registerInstance<EventBeatFactory>(asynchronousBeatFactory, "asynchronous");
|
||||||
|
|
||||||
|
contextContainer->registerInstance<std::shared_ptr<EventBeat>>(std::make_shared<MainRunLoopEventBeat>(), "synchronous");
|
||||||
|
contextContainer->registerInstance<std::shared_ptr<EventBeat>>(std::make_shared<MessageQueueEventBeat>(bridge.jsMessageThread), "asynchronous");
|
||||||
|
|
||||||
void *imageLoader = (__bridge void *)[[RCTBridge currentBridge] imageLoader];
|
void *imageLoader = (__bridge void *)[[RCTBridge currentBridge] imageLoader];
|
||||||
contextContainer->registerInstance(std::make_shared<ImageManager>(imageLoader));
|
contextContainer->registerInstance(std::make_shared<ImageManager>(imageLoader));
|
||||||
|
|
||||||
|
|
|
@ -80,16 +80,16 @@ static const std::string componentNameByReactViewName(std::string viewName) {
|
||||||
return viewName;
|
return viewName;
|
||||||
}
|
}
|
||||||
|
|
||||||
FabricUIManager::FabricUIManager(SharedComponentDescriptorRegistry componentDescriptorRegistry) {
|
|
||||||
componentDescriptorRegistry_ = componentDescriptorRegistry;
|
|
||||||
}
|
|
||||||
|
|
||||||
FabricUIManager::~FabricUIManager() {
|
FabricUIManager::~FabricUIManager() {
|
||||||
if (eventHandler_) {
|
if (eventHandler_) {
|
||||||
releaseEventHandlerFunction_(eventHandler_);
|
releaseEventHandlerFunction_(eventHandler_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FabricUIManager::setComponentDescriptorRegistry(const SharedComponentDescriptorRegistry &componentDescriptorRegistry) {
|
||||||
|
componentDescriptorRegistry_ = componentDescriptorRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
void FabricUIManager::setDelegate(UIManagerDelegate *delegate) {
|
void FabricUIManager::setDelegate(UIManagerDelegate *delegate) {
|
||||||
delegate_ = delegate;
|
delegate_ = delegate;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,9 +28,10 @@ public:
|
||||||
|
|
||||||
#pragma mark - Native-facing Interface
|
#pragma mark - Native-facing Interface
|
||||||
|
|
||||||
FabricUIManager(SharedComponentDescriptorRegistry componentDescriptorRegistry);
|
|
||||||
~FabricUIManager();
|
~FabricUIManager();
|
||||||
|
|
||||||
|
void setComponentDescriptorRegistry(const SharedComponentDescriptorRegistry &componentDescriptorRegistry);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sets and gets the UIManager's delegate.
|
* Sets and gets the UIManager's delegate.
|
||||||
* The delegate is stored as a raw pointer, so the owner must null
|
* The delegate is stored as a raw pointer, so the owner must null
|
||||||
|
|
|
@ -17,19 +17,31 @@ namespace react {
|
||||||
|
|
||||||
Scheduler::Scheduler(const SharedContextContainer &contextContainer):
|
Scheduler::Scheduler(const SharedContextContainer &contextContainer):
|
||||||
contextContainer_(contextContainer) {
|
contextContainer_(contextContainer) {
|
||||||
const auto &eventDispatcher = std::make_shared<SchedulerEventDispatcher>();
|
|
||||||
const auto &componentDescriptorRegistry = ComponentDescriptorFactory::buildRegistry(eventDispatcher, contextContainer);
|
|
||||||
|
|
||||||
uiManager_ = std::make_shared<FabricUIManager>(componentDescriptorRegistry);
|
uiManager_ = std::make_shared<FabricUIManager>();
|
||||||
|
|
||||||
|
auto eventDispatcher =
|
||||||
|
std::make_shared<EventDispatcher>(
|
||||||
|
std::bind(
|
||||||
|
&FabricUIManager::dispatchEventToTarget,
|
||||||
|
uiManager_.get(),
|
||||||
|
std::placeholders::_1,
|
||||||
|
std::placeholders::_2,
|
||||||
|
std::placeholders::_3
|
||||||
|
),
|
||||||
|
contextContainer->getInstance<EventBeatFactory>("synchronous"),
|
||||||
|
contextContainer->getInstance<EventBeatFactory>("asynchronous")
|
||||||
|
);
|
||||||
|
|
||||||
|
uiManager_->setComponentDescriptorRegistry(
|
||||||
|
ComponentDescriptorFactory::buildRegistry(eventDispatcher, contextContainer)
|
||||||
|
);
|
||||||
|
|
||||||
uiManager_->setDelegate(this);
|
uiManager_->setDelegate(this);
|
||||||
|
|
||||||
eventDispatcher->setUIManager(uiManager_);
|
|
||||||
eventDispatcher_ = eventDispatcher;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Scheduler::~Scheduler() {
|
Scheduler::~Scheduler() {
|
||||||
uiManager_->setDelegate(nullptr);
|
uiManager_->setDelegate(nullptr);
|
||||||
eventDispatcher_->setUIManager(nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scheduler::registerRootTag(Tag rootTag) {
|
void Scheduler::registerRootTag(Tag rootTag) {
|
||||||
|
|
|
@ -71,7 +71,7 @@ private:
|
||||||
SchedulerDelegate *delegate_;
|
SchedulerDelegate *delegate_;
|
||||||
std::shared_ptr<FabricUIManager> uiManager_;
|
std::shared_ptr<FabricUIManager> uiManager_;
|
||||||
std::unordered_map<Tag, SharedShadowTree> shadowTreeRegistry_;
|
std::unordered_map<Tag, SharedShadowTree> shadowTreeRegistry_;
|
||||||
SharedSchedulerEventDispatcher eventDispatcher_;
|
SharedEventDispatcher eventDispatcher_;
|
||||||
SharedContextContainer contextContainer_;
|
SharedContextContainer contextContainer_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue