Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ typedef std::shared_ptr<facebook::react::JSRuntimeFactory> (^RCTHostJSEngineProv

- (void)callFunctionOnJSModule:(NSString *)moduleName method:(NSString *)method args:(NSArray *)args;

/**
* The CallInvoker of the current React instance, the same one its TurboModules receive. It schedules work on the JS
* thread with a priority. The returned invoker can be used from any thread. Null before `start` and while a reload
* replaces the instance; every reload creates a new invoker, so read it again after `hostDidStart:`. Holding it past a
* reload or past the host's lifetime is safe: work sent to an invoker whose instance is gone is dropped.
*/
- (std::shared_ptr<facebook::react::CallInvoker>)jsCallInvoker;

// Renderer API

- (RCTFabricSurface *)createSurfaceWithModuleName:(NSString *)moduleName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,12 @@ - (void)callFunctionOnJSModule:(NSString *)moduleName method:(NSString *)method
[_instance callFunctionOnJSModule:moduleName method:method args:args];
}

- (std::shared_ptr<facebook::react::CallInvoker>)jsCallInvoker
{
RCTInstance *instance = _instance;
return instance ? instance.jsCallInvoker : nullptr;
}

#pragma mark - RCTReloadListener

- (void)didReceiveReloadCommand
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#import <React/RCTDefines.h>
#import <React/RCTJavaScriptLoader.h>
#import <ReactCommon/CallInvoker.h>
#import <jsinspector-modern/ReactCdp.h>
#import <react/runtime/JSRuntimeFactory.h>

Expand Down Expand Up @@ -85,6 +86,12 @@ NS_ASSUME_NONNULL_BEGIN

@property (nonatomic, readonly, strong) RCTSurfacePresenter *surfacePresenter;

/**
* The CallInvoker this instance hands to TurboModules. Schedules work on the JS thread with a priority, and can be
* called from any thread. Set during init; null once the instance is invalidated.
*/
@property (nonatomic, readonly) std::shared_ptr<facebook::react::CallInvoker> jsCallInvoker;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ @implementation RCTInstance {
RCTDisplayLink *_displayLink;
RCTTurboModuleManager *_turboModuleManager;
RCTBridgeProxy *_bridgeProxy;
std::shared_ptr<CallInvoker> _jsCallInvoker;
std::mutex _invalidationMutex;
std::atomic<bool> _valid;
RCTJSThreadManager *_jsThreadManager;
Expand Down Expand Up @@ -207,6 +208,11 @@ - (void)invalidate
}];
}

- (std::shared_ptr<CallInvoker>)jsCallInvoker
{
return _valid ? _jsCallInvoker : nullptr;
}

- (void)registerSegmentWithId:(NSNumber *)segmentId path:(NSString *)path
{
if (_valid) {
Expand Down Expand Up @@ -290,6 +296,7 @@ - (void)_start
timerManager->setRuntimeExecutor(bufferedRuntimeExecutor);

auto jsCallInvoker = _reactInstance->createJSCallInvoker();
_jsCallInvoker = jsCallInvoker;
RCTBridgeProxy *bridgeProxy =
[[RCTBridgeProxy alloc] initWithViewRegistry:_bridgeModuleDecorator.viewRegistry_DEPRECATED
moduleRegistry:_bridgeModuleDecorator.moduleRegistry
Expand Down
2 changes: 2 additions & 0 deletions scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,7 @@ interface RCTHost : public NSObject {
public virtual instancetype initWithBundleURL:hostDelegate:turboModuleManagerDelegate:jsEngineProvider:launchOptions:(NSURL* bundleURL, id<RCTHostDelegate> hostDelegate, id<RCTTurboModuleManagerDelegate> turboModuleManagerDelegate, RCTHostJSEngineProvider jsEngineProvider, _Nullable NSDictionary* launchOptions);
public virtual instancetype initWithBundleURLProvider:hostDelegate:turboModuleManagerDelegate:jsEngineProvider:launchOptions:(RCTHostBundleURLProvider provider, id<RCTHostDelegate> hostDelegate, id<RCTTurboModuleManagerDelegate> turboModuleManagerDelegate, RCTHostJSEngineProvider jsEngineProvider, _Nullable NSDictionary* launchOptions);
public virtual instancetype initWithBundleURLProvider:hostDelegate:turboModuleManagerDelegate:jsEngineProvider:launchOptions:bundleConfiguration:devMenuConfiguration:(RCTHostBundleURLProvider provider, id<RCTHostDelegate> hostDelegate, id<RCTTurboModuleManagerDelegate> turboModuleManagerDelegate, RCTHostJSEngineProvider jsEngineProvider, _Nullable NSDictionary* launchOptions, RCTBundleConfiguration* bundleConfiguration, RCTDevMenuConfiguration* devMenuConfiguration);
public virtual std::shared_ptr<facebook::react::CallInvoker> jsCallInvoker();
public virtual void callFunctionOnJSModule:method:args:(NSString* moduleName, NSString* method, NSArray* args);
public virtual void start();
}
Expand Down Expand Up @@ -1258,6 +1259,7 @@ interface RCTInspectorWebSocketReporter : public NSObject {
}

interface RCTInstance : public NSObject {
public @property (assign, readonly) std::shared_ptr<facebook::react::CallInvoker> jsCallInvoker;
public @property (strong, readonly) RCTSurfacePresenter* surfacePresenter;
public virtual instancetype initWithDelegate:jsRuntimeFactory:bundleManager:turboModuleManagerDelegate:moduleRegistry:parentInspectorTarget:launchOptions:(id<RCTInstanceDelegate> delegate, std::shared_ptr<facebook::react::JSRuntimeFactory> jsRuntimeFactory, RCTBundleManager* bundleManager, id<RCTTurboModuleManagerDelegate> turboModuleManagerDelegate, RCTModuleRegistry* moduleRegistry, facebook::react::jsinspector_modern::HostTarget* parentInspectorTarget, _Nullable NSDictionary* launchOptions);
public virtual instancetype initWithDelegate:jsRuntimeFactory:bundleManager:turboModuleManagerDelegate:moduleRegistry:parentInspectorTarget:launchOptions:devMenuConfiguration:(id<RCTInstanceDelegate> delegate, std::shared_ptr<facebook::react::JSRuntimeFactory> jsRuntimeFactory, RCTBundleManager* bundleManager, id<RCTTurboModuleManagerDelegate> turboModuleManagerDelegate, RCTModuleRegistry* moduleRegistry, facebook::react::jsinspector_modern::HostTarget* parentInspectorTarget, _Nullable NSDictionary* launchOptions, RCTDevMenuConfiguration* _Nullable devMenuConfiguration);
Expand Down
2 changes: 2 additions & 0 deletions scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,7 @@ interface RCTHost : public NSObject {
public virtual instancetype initWithBundleURL:hostDelegate:turboModuleManagerDelegate:jsEngineProvider:launchOptions:(NSURL* bundleURL, id<RCTHostDelegate> hostDelegate, id<RCTTurboModuleManagerDelegate> turboModuleManagerDelegate, RCTHostJSEngineProvider jsEngineProvider, _Nullable NSDictionary* launchOptions);
public virtual instancetype initWithBundleURLProvider:hostDelegate:turboModuleManagerDelegate:jsEngineProvider:launchOptions:(RCTHostBundleURLProvider provider, id<RCTHostDelegate> hostDelegate, id<RCTTurboModuleManagerDelegate> turboModuleManagerDelegate, RCTHostJSEngineProvider jsEngineProvider, _Nullable NSDictionary* launchOptions);
public virtual instancetype initWithBundleURLProvider:hostDelegate:turboModuleManagerDelegate:jsEngineProvider:launchOptions:bundleConfiguration:devMenuConfiguration:(RCTHostBundleURLProvider provider, id<RCTHostDelegate> hostDelegate, id<RCTTurboModuleManagerDelegate> turboModuleManagerDelegate, RCTHostJSEngineProvider jsEngineProvider, _Nullable NSDictionary* launchOptions, RCTBundleConfiguration* bundleConfiguration, RCTDevMenuConfiguration* devMenuConfiguration);
public virtual std::shared_ptr<facebook::react::CallInvoker> jsCallInvoker();
public virtual void callFunctionOnJSModule:method:args:(NSString* moduleName, NSString* method, NSArray* args);
public virtual void start();
}
Expand Down Expand Up @@ -1258,6 +1259,7 @@ interface RCTInspectorWebSocketReporter : public NSObject {
}

interface RCTInstance : public NSObject {
public @property (assign, readonly) std::shared_ptr<facebook::react::CallInvoker> jsCallInvoker;
public @property (strong, readonly) RCTSurfacePresenter* surfacePresenter;
public virtual instancetype initWithDelegate:jsRuntimeFactory:bundleManager:turboModuleManagerDelegate:moduleRegistry:parentInspectorTarget:launchOptions:(id<RCTInstanceDelegate> delegate, std::shared_ptr<facebook::react::JSRuntimeFactory> jsRuntimeFactory, RCTBundleManager* bundleManager, id<RCTTurboModuleManagerDelegate> turboModuleManagerDelegate, RCTModuleRegistry* moduleRegistry, facebook::react::jsinspector_modern::HostTarget* parentInspectorTarget, _Nullable NSDictionary* launchOptions);
public virtual instancetype initWithDelegate:jsRuntimeFactory:bundleManager:turboModuleManagerDelegate:moduleRegistry:parentInspectorTarget:launchOptions:devMenuConfiguration:(id<RCTInstanceDelegate> delegate, std::shared_ptr<facebook::react::JSRuntimeFactory> jsRuntimeFactory, RCTBundleManager* bundleManager, id<RCTTurboModuleManagerDelegate> turboModuleManagerDelegate, RCTModuleRegistry* moduleRegistry, facebook::react::jsinspector_modern::HostTarget* parentInspectorTarget, _Nullable NSDictionary* launchOptions, RCTDevMenuConfiguration* _Nullable devMenuConfiguration);
Expand Down
2 changes: 2 additions & 0 deletions scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,7 @@ interface RCTHost : public NSObject {
public virtual instancetype initWithBundleURL:hostDelegate:turboModuleManagerDelegate:jsEngineProvider:launchOptions:(NSURL* bundleURL, id<RCTHostDelegate> hostDelegate, id<RCTTurboModuleManagerDelegate> turboModuleManagerDelegate, RCTHostJSEngineProvider jsEngineProvider, _Nullable NSDictionary* launchOptions);
public virtual instancetype initWithBundleURLProvider:hostDelegate:turboModuleManagerDelegate:jsEngineProvider:launchOptions:(RCTHostBundleURLProvider provider, id<RCTHostDelegate> hostDelegate, id<RCTTurboModuleManagerDelegate> turboModuleManagerDelegate, RCTHostJSEngineProvider jsEngineProvider, _Nullable NSDictionary* launchOptions);
public virtual instancetype initWithBundleURLProvider:hostDelegate:turboModuleManagerDelegate:jsEngineProvider:launchOptions:bundleConfiguration:devMenuConfiguration:(RCTHostBundleURLProvider provider, id<RCTHostDelegate> hostDelegate, id<RCTTurboModuleManagerDelegate> turboModuleManagerDelegate, RCTHostJSEngineProvider jsEngineProvider, _Nullable NSDictionary* launchOptions, RCTBundleConfiguration* bundleConfiguration, RCTDevMenuConfiguration* devMenuConfiguration);
public virtual std::shared_ptr<facebook::react::CallInvoker> jsCallInvoker();
public virtual void callFunctionOnJSModule:method:args:(NSString* moduleName, NSString* method, NSArray* args);
public virtual void start();
}
Expand Down Expand Up @@ -1258,6 +1259,7 @@ interface RCTInspectorWebSocketReporter : public NSObject {
}

interface RCTInstance : public NSObject {
public @property (assign, readonly) std::shared_ptr<facebook::react::CallInvoker> jsCallInvoker;
public @property (strong, readonly) RCTSurfacePresenter* surfacePresenter;
public virtual instancetype initWithDelegate:jsRuntimeFactory:bundleManager:turboModuleManagerDelegate:moduleRegistry:parentInspectorTarget:launchOptions:(id<RCTInstanceDelegate> delegate, std::shared_ptr<facebook::react::JSRuntimeFactory> jsRuntimeFactory, RCTBundleManager* bundleManager, id<RCTTurboModuleManagerDelegate> turboModuleManagerDelegate, RCTModuleRegistry* moduleRegistry, facebook::react::jsinspector_modern::HostTarget* parentInspectorTarget, _Nullable NSDictionary* launchOptions);
public virtual instancetype initWithDelegate:jsRuntimeFactory:bundleManager:turboModuleManagerDelegate:moduleRegistry:parentInspectorTarget:launchOptions:devMenuConfiguration:(id<RCTInstanceDelegate> delegate, std::shared_ptr<facebook::react::JSRuntimeFactory> jsRuntimeFactory, RCTBundleManager* bundleManager, id<RCTTurboModuleManagerDelegate> turboModuleManagerDelegate, RCTModuleRegistry* moduleRegistry, facebook::react::jsinspector_modern::HostTarget* parentInspectorTarget, _Nullable NSDictionary* launchOptions, RCTDevMenuConfiguration* _Nullable devMenuConfiguration);
Expand Down
Loading