Skip to content

Commit 8f04699

Browse files
sherginfacebook-github-bot
authored andcommitted
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
1 parent 7a914fc commit 8f04699

File tree

9 files changed

+421
-8
lines changed

9 files changed

+421
-8
lines changed

React/Base/RCTBridge+Private.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ RCT_EXTERN void RCTRegisterModule(Class);
144144

145145
@interface RCTCxxBridge : RCTBridge
146146

147+
@property (nonatomic) void *runtime;
148+
147149
- (instancetype)initWithParentBridge:(RCTBridge *)bridge NS_DESIGNATED_INITIALIZER;
148150

149151
@end

React/CxxBridge/RCTCxxBridge.mm

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
typedef void (^RCTPendingCall)();
5858

5959
using namespace facebook::jsc;
60+
using namespace facebook::jsi;
6061
using namespace facebook::react;
6162

6263
/**
@@ -1229,4 +1230,13 @@ - (BOOL)isBatchActive
12291230
return _wasBatchActive;
12301231
}
12311232

1233+
- (void *)runtime
1234+
{
1235+
if (!_reactInstance) {
1236+
return nullptr;
1237+
}
1238+
1239+
return _reactInstance->getJavaScriptContext();
1240+
}
1241+
12321242
@end

React/Fabric/RCTSurfacePresenter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ NS_ASSUME_NONNULL_BEGIN
7979

8080
@end
8181

82-
@interface RCTBridge (RCTSurfacePresenter)
82+
@interface RCTBridge (Deprecated)
8383

84-
- (RCTSurfacePresenter *)surfacePresenter;
84+
@property (nonatomic) RCTSurfacePresenter *surfacePresenter;
8585

8686
@end
8787

React/Fabric/RCTSurfacePresenter.mm

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77

88
#import "RCTSurfacePresenter.h"
99

10+
#import <objc/runtime.h>
1011
#import <mutex>
12+
#import <jsi/jsi.h>
13+
#import <cxxreact/MessageQueueThread.h>
1114

1215
#import <React/RCTAssert.h>
1316
#import <React/RCTBridge+Private.h>
@@ -153,6 +156,14 @@ - (RCTScheduler *)_scheduler
153156
auto contextContainer = std::make_shared<ContextContainer>();
154157

155158
auto messageQueueThread = _batchedBridge.jsMessageThread;
159+
auto runtime = (facebook::jsi::Runtime *)((RCTCxxBridge *)_batchedBridge).runtime;
160+
161+
RuntimeExecutor runtimeExecutor =
162+
[runtime, messageQueueThread](std::function<void(facebook::jsi::Runtime &runtime)> &&callback) {
163+
messageQueueThread->runOnQueue([runtime, callback = std::move(callback)]() {
164+
callback(*runtime);
165+
});
166+
};
156167

157168
EventBeatFactory synchronousBeatFactory = [messageQueueThread]() {
158169
return std::make_unique<MainRunLoopEventBeat>(messageQueueThread);
@@ -165,8 +176,7 @@ - (RCTScheduler *)_scheduler
165176
contextContainer->registerInstance<EventBeatFactory>(synchronousBeatFactory, "synchronous");
166177
contextContainer->registerInstance<EventBeatFactory>(asynchronousBeatFactory, "asynchronous");
167178

168-
contextContainer->registerInstance(_uiManagerInstaller, "uimanager-installer");
169-
contextContainer->registerInstance(_uiManagerUninstaller, "uimanager-uninstaller");
179+
contextContainer->registerInstance(runtimeExecutor, "runtime-executor");
170180

171181
contextContainer->registerInstance(std::make_shared<ImageManager>((__bridge void *)[_bridge imageLoader]));
172182

@@ -307,3 +317,17 @@ - (RCTBridge *)bridge_DO_NOT_USE
307317
}
308318

309319
@end
320+
321+
@implementation RCTBridge (Deprecated)
322+
323+
- (void)setSurfacePresenter:(RCTSurfacePresenter *)surfacePresenter
324+
{
325+
objc_setAssociatedObject(self, @selector(surfacePresenter), surfacePresenter, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
326+
}
327+
328+
- (RCTSurfacePresenter *)surfacePresenter
329+
{
330+
return objc_getAssociatedObject(self, @selector(surfacePresenter));
331+
}
332+
333+
@end

ReactCommon/fabric/uimanager/BUCK

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ rn_xplat_cxx_library(
5555
"xplat//folly:headers_only",
5656
"xplat//folly:memory",
5757
"xplat//folly:molly",
58+
"xplat//jsi:JSIDynamic",
59+
"xplat//jsi:jsi",
5860
"xplat//third-party/glog:glog",
61+
react_native_xplat_target("cxxreact:bridge"),
5962
react_native_xplat_target("fabric/components/root:root"),
6063
react_native_xplat_target("fabric/components/view:view"),
6164
react_native_xplat_target("fabric/core:core"),

ReactCommon/fabric/uimanager/FabricUIManager.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <memory>
1111

1212
#include <folly/dynamic.h>
13+
#include <jsi/jsi.h>
1314

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

26+
using RuntimeExecutor = std::function<void(
27+
std::function<void(facebook::jsi::Runtime &runtime)> &&callback)>;
28+
2529
/*
2630
* Particular implementations of those functions should capture references to
2731
* the runtime and ensure proper threading.

0 commit comments

Comments
 (0)