Skip to content

Commit

Permalink
Fabric: New UIManager registration process (beginning)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
shergin authored and facebook-github-bot committed Oct 29, 2018
1 parent 7a914fc commit 8f04699
Show file tree
Hide file tree
Showing 9 changed files with 421 additions and 8 deletions.
2 changes: 2 additions & 0 deletions React/Base/RCTBridge+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ RCT_EXTERN void RCTRegisterModule(Class);

@interface RCTCxxBridge : RCTBridge

@property (nonatomic) void *runtime;

- (instancetype)initWithParentBridge:(RCTBridge *)bridge NS_DESIGNATED_INITIALIZER;

@end
10 changes: 10 additions & 0 deletions React/CxxBridge/RCTCxxBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
typedef void (^RCTPendingCall)();

using namespace facebook::jsc;
using namespace facebook::jsi;
using namespace facebook::react;

/**
Expand Down Expand Up @@ -1229,4 +1230,13 @@ - (BOOL)isBatchActive
return _wasBatchActive;
}

- (void *)runtime
{
if (!_reactInstance) {
return nullptr;
}

return _reactInstance->getJavaScriptContext();
}

@end
4 changes: 2 additions & 2 deletions React/Fabric/RCTSurfacePresenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ NS_ASSUME_NONNULL_BEGIN

@end

@interface RCTBridge (RCTSurfacePresenter)
@interface RCTBridge (Deprecated)

- (RCTSurfacePresenter *)surfacePresenter;
@property (nonatomic) RCTSurfacePresenter *surfacePresenter;

@end

Expand Down
28 changes: 26 additions & 2 deletions React/Fabric/RCTSurfacePresenter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -153,6 +156,14 @@ - (RCTScheduler *)_scheduler
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);
Expand All @@ -165,8 +176,7 @@ - (RCTScheduler *)_scheduler
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]));

Expand Down Expand Up @@ -307,3 +317,17 @@ - (RCTBridge *)bridge_DO_NOT_USE
}

@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
3 changes: 3 additions & 0 deletions ReactCommon/fabric/uimanager/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ rn_xplat_cxx_library(
"xplat//folly:headers_only",
"xplat//folly:memory",
"xplat//folly:molly",
"xplat//jsi:JSIDynamic",
"xplat//jsi:jsi",
"xplat//third-party/glog:glog",
react_native_xplat_target("cxxreact:bridge"),
react_native_xplat_target("fabric/components/root:root"),
react_native_xplat_target("fabric/components/view:view"),
react_native_xplat_target("fabric/core:core"),
Expand Down
4 changes: 4 additions & 0 deletions ReactCommon/fabric/uimanager/FabricUIManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <memory>

#include <folly/dynamic.h>
#include <jsi/jsi.h>

#include <fabric/core/ShadowNode.h>
#include <fabric/events/EventBeatBasedExecutor.h>
Expand All @@ -22,6 +23,9 @@ namespace react {
class FabricUIManager;
using UIManager = FabricUIManager;

using RuntimeExecutor = std::function<void(
std::function<void(facebook::jsi::Runtime &runtime)> &&callback)>;

/*
* Particular implementations of those functions should capture references to
* the runtime and ensure proper threading.
Expand Down
Loading

0 comments on commit 8f04699

Please sign in to comment.