Fabric: ContextContainer initialization was moved to RCTSurfacePresenter

Summary:
Several reasons:

* We are fulfilling a promise that RCTScheduler is just a very thin interop proxy between C++ and Objective-C;
* We have to pass all parameters down to Scheduler anyway, so instead of creating all of them separately and then passing one-by-one, we consolidate them into Context created where we have all those values.

In the future, we probably will move it to some dedicated place.

Reviewed By: mdvacca

Differential Revision: D9884892

fbshipit-source-id: f1d5744e4044bc4bdfe53ec9a97ee61dcf0c60c2
This commit is contained in:
Valentin Shergin 2018-09-24 12:54:26 -07:00 committed by Facebook Github Bot
parent 60a4faa578
commit 55e168980f
3 changed files with 34 additions and 34 deletions

View File

@ -37,6 +37,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (atomic, weak, nullable) id<RCTSchedulerDelegate> delegate;
- (instancetype)initWithContextContainer:(std::shared_ptr<void>)contextContatiner;
- (void)registerRootTag:(ReactTag)tag;
- (void)unregisterRootTag:(ReactTag)tag;

View File

@ -7,28 +7,18 @@
#import "RCTScheduler.h"
#import <fabric/imagemanager/ImageManager.h>
#import <fabric/uimanager/ContextContainer.h>
#import <fabric/uimanager/Scheduler.h>
#import <fabric/uimanager/SchedulerDelegate.h>
#import <React/RCTImageLoader.h>
#import <React/RCTBridge+Private.h>
#import "MainRunLoopEventBeat.h"
#import "MessageQueueEventBeat.h"
#import "RCTConversions.h"
@interface RCTBridge ()
- (std::shared_ptr<facebook::react::MessageQueueThread>)jsMessageThread;
@end
using namespace facebook::react;
class SchedulerDelegateProxy: public SchedulerDelegate {
public:
SchedulerDelegateProxy(void *scheduler): scheduler_(scheduler) {}
SchedulerDelegateProxy(void *scheduler):
scheduler_(scheduler) {}
void schedulerDidFinishTransaction(Tag rootTag, const ShadowViewMutationList &mutations) override {
RCTScheduler *scheduler = (__bridge RCTScheduler *)scheduler_;
@ -49,30 +39,11 @@ private:
std::shared_ptr<SchedulerDelegateProxy> _delegateProxy;
}
- (instancetype)init
- (instancetype)initWithContextContainer:(std::shared_ptr<void>)contextContatiner
{
if (self = [super init]) {
_delegateProxy = std::make_shared<SchedulerDelegateProxy>((__bridge void *)self);
RCTBridge *bridge = [RCTBridge currentBridge];
SharedContextContainer contextContainer = std::make_shared<ContextContainer>();
EventBeatFactory synchronousBeatFactory = [bridge]() {
return std::make_unique<MainRunLoopEventBeat>(bridge.jsMessageThread);
};
EventBeatFactory asynchronousBeatFactory = [bridge]() {
return std::make_unique<MessageQueueEventBeat>(bridge.jsMessageThread);
};
contextContainer->registerInstance<EventBeatFactory>(synchronousBeatFactory, "synchronous");
contextContainer->registerInstance<EventBeatFactory>(asynchronousBeatFactory, "asynchronous");
void *imageLoader = (__bridge void *)[[RCTBridge currentBridge] imageLoader];
contextContainer->registerInstance(std::make_shared<ImageManager>(imageLoader));
_scheduler = std::make_shared<Scheduler>(contextContainer);
_scheduler = std::make_shared<Scheduler>(std::static_pointer_cast<ContextContainer>(contextContatiner));
_scheduler->setDelegate(_delegateProxy.get());
}

View File

@ -11,6 +11,7 @@
#import <React/RCTBridge+Private.h>
#import <React/RCTComponentViewRegistry.h>
#import <React/RCTFabricSurface.h>
#import <React/RCTImageLoader.h>
#import <React/RCTMountingManager.h>
#import <React/RCTMountingManagerDelegate.h>
#import <React/RCTScheduler.h>
@ -20,11 +21,19 @@
#import <React/RCTUtils.h>
#import <fabric/core/LayoutContext.h>
#import <fabric/core/LayoutConstraints.h>
#import <fabric/imagemanager/ImageManager.h>
#import <fabric/uimanager/ContextContainer.h>
#import "MainRunLoopEventBeat.h"
#import "MessageQueueEventBeat.h"
#import "RCTConversions.h"
using namespace facebook::react;
@interface RCTBridge ()
- (std::shared_ptr<facebook::react::MessageQueueThread>)jsMessageThread;
@end
@interface RCTSurfacePresenter () <RCTSchedulerDelegate, RCTMountingManagerDelegate>
@end
@ -42,7 +51,25 @@ using namespace facebook::react;
_bridge = bridge;
_batchedBridge = [_bridge batchedBridge] ?: _bridge;
_scheduler = [[RCTScheduler alloc] init];
auto contextContainer = std::make_shared<ContextContainer>();
auto messageQueueThread = _batchedBridge.jsMessageThread;
EventBeatFactory synchronousBeatFactory = [messageQueueThread]() {
return std::make_unique<MainRunLoopEventBeat>(messageQueueThread);
};
EventBeatFactory asynchronousBeatFactory = [messageQueueThread]() {
return std::make_unique<MessageQueueEventBeat>(messageQueueThread);
};
contextContainer->registerInstance<EventBeatFactory>(synchronousBeatFactory, "synchronous");
contextContainer->registerInstance<EventBeatFactory>(asynchronousBeatFactory, "asynchronous");
void *imageLoader = (__bridge void *)[[RCTBridge currentBridge] imageLoader];
contextContainer->registerInstance(std::make_shared<ImageManager>(imageLoader));
_scheduler = [[RCTScheduler alloc] initWithContextContainer:contextContainer];
_scheduler.delegate = self;
_surfaceRegistry = [[RCTSurfaceRegistry alloc] init];