Skip to content

Commit f4f4b95

Browse files
javachemeta-codesync[bot]
authored andcommitted
Migrate RCTBlobManager to RCTTurboModuleWithJSIBindings (#56575)
Summary: Pull Request resolved: #56575 Migrates RCTBlobManager on iOS from using private API (RCTBridge+Private.h / RCTCxxBridge) to using the standardized RCTTurboModuleWithJSIBindings protocol for installing JSI bindings. This aligns with the Android implementation and removes dependency on private React API. Changelog: [Internal] Reviewed By: sammy-SC Differential Revision: D102145286 fbshipit-source-id: 9907f5a2f64ae55741e25d9b96ae42e94e7e5385
1 parent c0adcea commit f4f4b95

5 files changed

Lines changed: 28 additions & 31 deletions

File tree

packages/react-native/Libraries/Blob/RCTBlobCollector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class JSI_EXPORT RCTBlobCollector : public jsi::HostObject {
1616
RCTBlobCollector(RCTBlobManager *blobManager, const std::string &blobId);
1717
~RCTBlobCollector();
1818

19-
static void install(RCTBlobManager *blobManager);
19+
static void install(jsi::Runtime &runtime, RCTBlobManager *blobManager);
2020

2121
private:
2222
const std::string blobId_;

packages/react-native/Libraries/Blob/RCTBlobCollector.mm

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#import "RCTBlobCollector.h"
99

1010
#import <React/RCTBlobManager.h>
11-
#import <React/RCTBridge+Private.h>
1211

1312
namespace facebook::react {
1413

@@ -26,32 +25,21 @@
2625
});
2726
}
2827

29-
void RCTBlobCollector::install(RCTBlobManager *blobManager)
28+
void RCTBlobCollector::install(jsi::Runtime &runtime, RCTBlobManager *blobManager)
3029
{
31-
__weak RCTCxxBridge *cxxBridge = (RCTCxxBridge *)blobManager.bridge;
32-
[cxxBridge
33-
dispatchBlock:^{
34-
if ((cxxBridge == nullptr) || cxxBridge.runtime == nullptr) {
35-
return;
36-
}
37-
jsi::Runtime &runtime = *(jsi::Runtime *)cxxBridge.runtime;
38-
runtime.global().setProperty(
39-
runtime,
40-
"__blobCollectorProvider",
41-
jsi::Function::createFromHostFunction(
42-
runtime,
43-
jsi::PropNameID::forAscii(runtime, "__blobCollectorProvider"),
44-
1,
45-
[blobManager](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) {
46-
auto blobId = args[0].asString(rt).utf8(rt);
47-
auto blobCollector = std::make_shared<RCTBlobCollector>(blobManager, blobId);
48-
auto blobCollectorJsObject = jsi::Object::createFromHostObject(rt, blobCollector);
49-
blobCollectorJsObject.setExternalMemoryPressure(
50-
rt, [blobManager lengthOfBlobWithId:[NSString stringWithUTF8String:blobId.c_str()]]);
51-
return blobCollectorJsObject;
52-
}));
53-
}
54-
queue:RCTJSThread];
30+
auto provider = jsi::Function::createFromHostFunction(
31+
runtime,
32+
jsi::PropNameID::forAscii(runtime, "__blobCollectorProvider"),
33+
1,
34+
[blobManager](jsi::Runtime &rt, const jsi::Value & /*thisVal*/, const jsi::Value *args, size_t /*count*/) {
35+
auto blobId = args[0].asString(rt).utf8(rt);
36+
auto blobCollector = std::make_shared<RCTBlobCollector>(blobManager, blobId);
37+
auto blobCollectorJsObject = jsi::Object::createFromHostObject(rt, blobCollector);
38+
blobCollectorJsObject.setExternalMemoryPressure(
39+
rt, [blobManager lengthOfBlobWithId:[NSString stringWithUTF8String:blobId.c_str()]]);
40+
return blobCollectorJsObject;
41+
});
42+
runtime.global().setProperty(runtime, "__blobCollectorProvider", std::move(provider));
5543
}
5644

5745
} // namespace facebook::react

packages/react-native/Libraries/Blob/RCTBlobManager.mm

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#import "RCTBlobCollector.h"
2020
#import "RCTBlobPlugins.h"
2121

22+
#import <ReactCommon/RCTTurboModuleWithJSIBindings.h>
23+
2224
RCT_MOCK_DEF(RCTBlobManager, dispatch_async);
2325
#define dispatch_async RCT_MOCK_USE(RCTBlobManager, dispatch_async)
2426

@@ -28,7 +30,8 @@ @interface RCTBlobManager () <
2830
RCTNetworkingRequestHandler,
2931
RCTNetworkingResponseHandler,
3032
RCTWebSocketContentHandler,
31-
NativeBlobModuleSpec>
33+
NativeBlobModuleSpec,
34+
RCTTurboModuleWithJSIBindings>
3235

3336
@end
3437

@@ -52,7 +55,6 @@ - (void)initialize
5255
{
5356
std::lock_guard<std::mutex> lock(_blobsMutex);
5457
_blobs = [NSMutableDictionary new];
55-
facebook::react::RCTBlobCollector::install(self);
5658
}
5759

5860
+ (BOOL)requiresMainQueueSetup
@@ -333,6 +335,13 @@ - (id)processWebsocketMessage:(id)message
333335
return std::make_shared<facebook::react::NativeBlobModuleSpecJSI>(params);
334336
}
335337

338+
#pragma mark - RCTTurboModuleWithJSIBindings
339+
340+
- (void)installJSIBindingsWithRuntime:(facebook::jsi::Runtime &)runtime
341+
callInvoker:(const std::shared_ptr<facebook::react::CallInvoker> &)callInvoker
342+
{
343+
facebook::react::RCTBlobCollector::install(runtime, self);
344+
}
336345
@end
337346

338347
Class RCTBlobManagerCls(void)

scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6703,7 +6703,7 @@ class facebook::react::RAMBundleRegistry {
67036703

67046704
class facebook::react::RCTBlobCollector : public facebook::jsi::HostObject {
67056705
public RCTBlobCollector(RCTBlobManager* blobManager, const std::string& blobId);
6706-
public static void install(RCTBlobManager* blobManager);
6706+
public static void install(facebook::jsi::Runtime& runtime, RCTBlobManager* blobManager);
67076707
public ~RCTBlobCollector();
67086708
}
67096709

scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6700,7 +6700,7 @@ class facebook::react::RAMBundleRegistry {
67006700

67016701
class facebook::react::RCTBlobCollector : public facebook::jsi::HostObject {
67026702
public RCTBlobCollector(RCTBlobManager* blobManager, const std::string& blobId);
6703-
public static void install(RCTBlobManager* blobManager);
6703+
public static void install(facebook::jsi::Runtime& runtime, RCTBlobManager* blobManager);
67046704
public ~RCTBlobCollector();
67056705
}
67066706

0 commit comments

Comments
 (0)