expose contextContainer as application API
Summary: We need a way for different apps to inject dependencies or additional functionality into Fabric - ReactNativeConfig might be a special case, but I think this could clean up it's integration nicely, and I'm using this for a uitemplate cache system so we can use CompactDisk or other storage systems for caching depending on the app. Reviewed By: mdvacca Differential Revision: D13407287 fbshipit-source-id: 45481908434e6235850aa4d2d6b2bfb936a23be7
This commit is contained in:
parent
fa31e44e13
commit
089dba3842
|
@ -10,6 +10,7 @@
|
|||
|
||||
#import <React/RCTBridge.h>
|
||||
#import <React/RCTComponentViewFactory.h>
|
||||
#import <react/uimanager/ContextContainer.h>
|
||||
#import <React/RCTPrimitives.h>
|
||||
#import <react/config/ReactNativeConfig.h>
|
||||
|
||||
|
@ -30,6 +31,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
config:(std::shared_ptr<const facebook::react::ReactNativeConfig>)config;
|
||||
|
||||
@property (nonatomic, readonly) RCTComponentViewFactory *componentViewFactory;
|
||||
@property (nonatomic, readonly) facebook::react::SharedContextContainer contextContainer;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ using namespace facebook::react;
|
|||
|
||||
@implementation RCTSurfacePresenter {
|
||||
std::mutex _schedulerMutex;
|
||||
std::mutex _contextContainerMutex;
|
||||
RCTScheduler *_Nullable _scheduler; // Thread-safe. Mutation of the instance variable is protected by `_schedulerMutex`.
|
||||
RCTMountingManager *_mountingManager; // Thread-safe.
|
||||
RCTSurfaceRegistry *_surfaceRegistry; // Thread-safe.
|
||||
|
@ -166,9 +167,25 @@ using namespace facebook::react;
|
|||
return _scheduler;
|
||||
}
|
||||
|
||||
auto contextContainer = std::make_shared<ContextContainer>();
|
||||
_scheduler = [[RCTScheduler alloc] initWithContextContainer:self.contextContainer];
|
||||
_scheduler.delegate = self;
|
||||
|
||||
contextContainer->registerInstance(_reactNativeConfig);
|
||||
return _scheduler;
|
||||
}
|
||||
|
||||
@synthesize contextContainer = _contextContainer;
|
||||
|
||||
- (SharedContextContainer)contextContainer
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_contextContainerMutex);
|
||||
|
||||
if (_contextContainer) {
|
||||
return _contextContainer;
|
||||
}
|
||||
|
||||
_contextContainer = std::make_shared<ContextContainer>();
|
||||
|
||||
_contextContainer->registerInstance(_reactNativeConfig);
|
||||
|
||||
auto messageQueueThread = _batchedBridge.jsMessageThread;
|
||||
auto runtime = (facebook::jsi::Runtime *)((RCTCxxBridge *)_batchedBridge).runtime;
|
||||
|
@ -188,17 +205,13 @@ using namespace facebook::react;
|
|||
return std::make_unique<RuntimeEventBeat>(runtimeExecutor);
|
||||
};
|
||||
|
||||
contextContainer->registerInstance<EventBeatFactory>(synchronousBeatFactory, "synchronous");
|
||||
contextContainer->registerInstance<EventBeatFactory>(asynchronousBeatFactory, "asynchronous");
|
||||
_contextContainer->registerInstance<EventBeatFactory>(synchronousBeatFactory, "synchronous");
|
||||
_contextContainer->registerInstance<EventBeatFactory>(asynchronousBeatFactory, "asynchronous");
|
||||
|
||||
contextContainer->registerInstance(runtimeExecutor, "runtime-executor");
|
||||
_contextContainer->registerInstance(runtimeExecutor, "runtime-executor");
|
||||
|
||||
contextContainer->registerInstance(std::make_shared<ImageManager>((__bridge void *)[_bridge imageLoader]));
|
||||
|
||||
_scheduler = [[RCTScheduler alloc] initWithContextContainer:contextContainer];
|
||||
_scheduler.delegate = self;
|
||||
|
||||
return _scheduler;
|
||||
_contextContainer->registerInstance(std::make_shared<ImageManager>((__bridge void *)[_bridge imageLoader]));
|
||||
return _contextContainer;
|
||||
}
|
||||
|
||||
- (void)_startSurface:(RCTFabricSurface *)surface
|
||||
|
@ -308,6 +321,7 @@ using namespace facebook::react;
|
|||
{
|
||||
std::lock_guard<std::mutex> lock(_schedulerMutex);
|
||||
_scheduler = nil;
|
||||
_contextContainer = nil;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,8 +18,7 @@
|
|||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
Scheduler::Scheduler(const SharedContextContainer &contextContainer)
|
||||
: contextContainer_(contextContainer) {
|
||||
Scheduler::Scheduler(const SharedContextContainer &contextContainer) {
|
||||
const auto asynchronousEventBeatFactory =
|
||||
contextContainer->getInstance<EventBeatFactory>("asynchronous");
|
||||
const auto synchronousEventBeatFactory =
|
||||
|
|
|
@ -92,7 +92,6 @@ class Scheduler final : public UIManagerDelegate, public ShadowTreeDelegate {
|
|||
SchedulerDelegate *delegate_;
|
||||
SharedComponentDescriptorRegistry componentDescriptorRegistry_;
|
||||
ShadowTreeRegistry shadowTreeRegistry_;
|
||||
SharedContextContainer contextContainer_;
|
||||
RuntimeExecutor runtimeExecutor_;
|
||||
std::shared_ptr<UIManagerBinding> uiManagerBinding_;
|
||||
std::shared_ptr<const ReactNativeConfig> reactNativeConfig_;
|
||||
|
|
Loading…
Reference in New Issue