From 55e168980fb727c1a6cd135f51a82ca090a80d74 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Mon, 24 Sep 2018 12:54:26 -0700 Subject: [PATCH] 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 --- React/Fabric/RCTScheduler.h | 2 ++ React/Fabric/RCTScheduler.mm | 37 ++++------------------------- React/Fabric/RCTSurfacePresenter.mm | 29 +++++++++++++++++++++- 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/React/Fabric/RCTScheduler.h b/React/Fabric/RCTScheduler.h index 65d0b6dab..cee65a22e 100644 --- a/React/Fabric/RCTScheduler.h +++ b/React/Fabric/RCTScheduler.h @@ -37,6 +37,8 @@ NS_ASSUME_NONNULL_BEGIN @property (atomic, weak, nullable) id delegate; +- (instancetype)initWithContextContainer:(std::shared_ptr)contextContatiner; + - (void)registerRootTag:(ReactTag)tag; - (void)unregisterRootTag:(ReactTag)tag; diff --git a/React/Fabric/RCTScheduler.mm b/React/Fabric/RCTScheduler.mm index 8af8a92cd..d1aa3a043 100644 --- a/React/Fabric/RCTScheduler.mm +++ b/React/Fabric/RCTScheduler.mm @@ -7,28 +7,18 @@ #import "RCTScheduler.h" -#import #import #import #import -#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 { 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 _delegateProxy; } -- (instancetype)init +- (instancetype)initWithContextContainer:(std::shared_ptr)contextContatiner { if (self = [super init]) { _delegateProxy = std::make_shared((__bridge void *)self); - - RCTBridge *bridge = [RCTBridge currentBridge]; - - SharedContextContainer contextContainer = std::make_shared(); - - EventBeatFactory synchronousBeatFactory = [bridge]() { - return std::make_unique(bridge.jsMessageThread); - }; - - EventBeatFactory asynchronousBeatFactory = [bridge]() { - return std::make_unique(bridge.jsMessageThread); - }; - - contextContainer->registerInstance(synchronousBeatFactory, "synchronous"); - contextContainer->registerInstance(asynchronousBeatFactory, "asynchronous"); - - void *imageLoader = (__bridge void *)[[RCTBridge currentBridge] imageLoader]; - contextContainer->registerInstance(std::make_shared(imageLoader)); - - _scheduler = std::make_shared(contextContainer); + _scheduler = std::make_shared(std::static_pointer_cast(contextContatiner)); _scheduler->setDelegate(_delegateProxy.get()); } diff --git a/React/Fabric/RCTSurfacePresenter.mm b/React/Fabric/RCTSurfacePresenter.mm index 27dc79318..59891c024 100644 --- a/React/Fabric/RCTSurfacePresenter.mm +++ b/React/Fabric/RCTSurfacePresenter.mm @@ -11,6 +11,7 @@ #import #import #import +#import #import #import #import @@ -20,11 +21,19 @@ #import #import #import +#import +#import +#import "MainRunLoopEventBeat.h" +#import "MessageQueueEventBeat.h" #import "RCTConversions.h" using namespace facebook::react; +@interface RCTBridge () +- (std::shared_ptr)jsMessageThread; +@end + @interface RCTSurfacePresenter () @end @@ -42,7 +51,25 @@ using namespace facebook::react; _bridge = bridge; _batchedBridge = [_bridge batchedBridge] ?: _bridge; - _scheduler = [[RCTScheduler alloc] init]; + auto contextContainer = std::make_shared(); + + auto messageQueueThread = _batchedBridge.jsMessageThread; + + EventBeatFactory synchronousBeatFactory = [messageQueueThread]() { + return std::make_unique(messageQueueThread); + }; + + EventBeatFactory asynchronousBeatFactory = [messageQueueThread]() { + return std::make_unique(messageQueueThread); + }; + + contextContainer->registerInstance(synchronousBeatFactory, "synchronous"); + contextContainer->registerInstance(asynchronousBeatFactory, "asynchronous"); + + void *imageLoader = (__bridge void *)[[RCTBridge currentBridge] imageLoader]; + contextContainer->registerInstance(std::make_shared(imageLoader)); + + _scheduler = [[RCTScheduler alloc] initWithContextContainer:contextContainer]; _scheduler.delegate = self; _surfaceRegistry = [[RCTSurfaceRegistry alloc] init];