Fabric: New UIManager registration process (beginning)

Summary:
This diff introduces a new integration concept (called RuntimeExecutor) which consolidates `Runtime` and the dispatching mechanism.
As simple as that:
`using RuntimeExecutor = std::function<void(std::function<void(facebook::jsi::Runtime &runtime)> &&callback)>;`

Reviewed By: fkgozali

Differential Revision: D12816746

fbshipit-source-id: 9e27ef16b98af861d494fe50c7e50bd0536e6aaf
This commit is contained in:
Valentin Shergin
2018-10-29 13:02:27 -07:00
committed by Facebook Github Bot
parent 7a914fcef4
commit 8f04699c4c
9 changed files with 421 additions and 8 deletions

View File

@@ -144,6 +144,8 @@ RCT_EXTERN void RCTRegisterModule(Class);
@interface RCTCxxBridge : RCTBridge
@property (nonatomic) void *runtime;
- (instancetype)initWithParentBridge:(RCTBridge *)bridge NS_DESIGNATED_INITIALIZER;
@end

View File

@@ -57,6 +57,7 @@ static NSString *const RCTJSThreadName = @"com.facebook.react.JavaScript";
typedef void (^RCTPendingCall)();
using namespace facebook::jsc;
using namespace facebook::jsi;
using namespace facebook::react;
/**
@@ -1229,4 +1230,13 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR
return _wasBatchActive;
}
- (void *)runtime
{
if (!_reactInstance) {
return nullptr;
}
return _reactInstance->getJavaScriptContext();
}
@end

View File

@@ -79,9 +79,9 @@ NS_ASSUME_NONNULL_BEGIN
@end
@interface RCTBridge (RCTSurfacePresenter)
@interface RCTBridge (Deprecated)
- (RCTSurfacePresenter *)surfacePresenter;
@property (nonatomic) RCTSurfacePresenter *surfacePresenter;
@end

View File

@@ -7,7 +7,10 @@
#import "RCTSurfacePresenter.h"
#import <objc/runtime.h>
#import <mutex>
#import <jsi/jsi.h>
#import <cxxreact/MessageQueueThread.h>
#import <React/RCTAssert.h>
#import <React/RCTBridge+Private.h>
@@ -153,6 +156,14 @@ using namespace facebook::react;
auto contextContainer = std::make_shared<ContextContainer>();
auto messageQueueThread = _batchedBridge.jsMessageThread;
auto runtime = (facebook::jsi::Runtime *)((RCTCxxBridge *)_batchedBridge).runtime;
RuntimeExecutor runtimeExecutor =
[runtime, messageQueueThread](std::function<void(facebook::jsi::Runtime &runtime)> &&callback) {
messageQueueThread->runOnQueue([runtime, callback = std::move(callback)]() {
callback(*runtime);
});
};
EventBeatFactory synchronousBeatFactory = [messageQueueThread]() {
return std::make_unique<MainRunLoopEventBeat>(messageQueueThread);
@@ -165,8 +176,7 @@ using namespace facebook::react;
contextContainer->registerInstance<EventBeatFactory>(synchronousBeatFactory, "synchronous");
contextContainer->registerInstance<EventBeatFactory>(asynchronousBeatFactory, "asynchronous");
contextContainer->registerInstance(_uiManagerInstaller, "uimanager-installer");
contextContainer->registerInstance(_uiManagerUninstaller, "uimanager-uninstaller");
contextContainer->registerInstance(runtimeExecutor, "runtime-executor");
contextContainer->registerInstance(std::make_shared<ImageManager>((__bridge void *)[_bridge imageLoader]));
@@ -307,3 +317,17 @@ using namespace facebook::react;
}
@end
@implementation RCTBridge (Deprecated)
- (void)setSurfacePresenter:(RCTSurfacePresenter *)surfacePresenter
{
objc_setAssociatedObject(self, @selector(surfacePresenter), surfacePresenter, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (RCTSurfacePresenter *)surfacePresenter
{
return objc_getAssociatedObject(self, @selector(surfacePresenter));
}
@end