mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-19 23:40:09 +08:00
Fabric: Lazy ContextContainer creation in RCTSurfacePresenter
Summary: Besides that it's more simple and straight-forward now, we need that to always instantiate Scheduler with a context full of fresh valid objects derived from the new instance of the bridge. Reviewed By: mdvacca Differential Revision: D9995780 fbshipit-source-id: 534a314152d93562b08dd7857962f174b0d06886
This commit is contained in:
committed by
Facebook Github Bot
parent
7420048b63
commit
08961c1e97
@@ -27,6 +27,12 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (instancetype)initWithBridge:(RCTBridge *)bridge;
|
||||
|
||||
/*
|
||||
* Deprecated. Do not use.
|
||||
*/
|
||||
@property (nonatomic) std::function<facebook::react::UIManagerInstaller> uiManagerInstaller;
|
||||
@property (nonatomic) std::function<facebook::react::UIManagerUninstaller> uiManagerUninstaller;
|
||||
|
||||
@end
|
||||
|
||||
@interface RCTSurfacePresenter (Surface)
|
||||
@@ -60,9 +66,6 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface RCTSurfacePresenter (Deprecated)
|
||||
|
||||
@property (nonatomic) std::function<facebook::react::UIManagerInstaller> uiManagerInstaller;
|
||||
@property (nonatomic) std::function<facebook::react::UIManagerUninstaller> uiManagerUninstaller;
|
||||
|
||||
/**
|
||||
* We need to expose `uiManager` for registration
|
||||
* purposes. Eventually, we will move this down to C++ side.
|
||||
|
||||
@@ -43,7 +43,6 @@ using namespace facebook::react;
|
||||
RCTBridge *_bridge;
|
||||
RCTBridge *_batchedBridge;
|
||||
RCTSurfaceRegistry *_surfaceRegistry;
|
||||
SharedContextContainer _contextContainer;
|
||||
}
|
||||
|
||||
- (instancetype)initWithBridge:(RCTBridge *)bridge
|
||||
@@ -52,26 +51,6 @@ using namespace facebook::react;
|
||||
_bridge = bridge;
|
||||
_batchedBridge = [_bridge batchedBridge] ?: _bridge;
|
||||
|
||||
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));
|
||||
|
||||
_contextContainer = contextContainer;
|
||||
|
||||
_surfaceRegistry = [[RCTSurfaceRegistry alloc] init];
|
||||
|
||||
_mountingManager = [[RCTMountingManager alloc] init];
|
||||
@@ -101,7 +80,27 @@ using namespace facebook::react;
|
||||
return;
|
||||
}
|
||||
|
||||
_scheduler = [[RCTScheduler alloc] initWithContextContainer:_contextContainer];
|
||||
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");
|
||||
|
||||
contextContainer->registerInstance(_uiManagerInstaller, "uimanager-installer");
|
||||
contextContainer->registerInstance(_uiManagerUninstaller, "uimanager-uninstaller");
|
||||
|
||||
contextContainer->registerInstance(std::make_shared<ImageManager>((__bridge void *)[_bridge imageLoader]));
|
||||
|
||||
_scheduler = [[RCTScheduler alloc] initWithContextContainer:contextContainer];
|
||||
_scheduler.delegate = self;
|
||||
}
|
||||
|
||||
@@ -294,26 +293,6 @@ using namespace facebook::react;
|
||||
return _bridge;
|
||||
}
|
||||
|
||||
- (void)setUiManagerInstaller:(std::function<facebook::react::UIManagerInstaller>)uiManagerInstaller
|
||||
{
|
||||
_contextContainer->registerInstance(uiManagerInstaller, "uimanager-installer");
|
||||
}
|
||||
|
||||
- (std::function<facebook::react::UIManagerInstaller>)uiManagerInstaller
|
||||
{
|
||||
return _contextContainer->getInstance<std::function<facebook::react::UIManagerInstaller>>("uimanager-installer");
|
||||
}
|
||||
|
||||
- (void)setUiManagerUninstaller:(std::function<facebook::react::UIManagerUninstaller>)uiManagerUninstaller
|
||||
{
|
||||
_contextContainer->registerInstance(uiManagerUninstaller, "uimanager-uninstaller");
|
||||
}
|
||||
|
||||
- (std::function<facebook::react::UIManagerUninstaller>)uiManagerUninstaller
|
||||
{
|
||||
return _contextContainer->getInstance<std::function<facebook::react::UIManagerUninstaller>>("uimanager-uninstaller");
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation RCTBridge (RCTSurfacePresenter)
|
||||
|
||||
Reference in New Issue
Block a user