Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/calm-dingos-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rnx-kit/react-native-host": patch
---

Post a notification when the React runtime is ready
27 changes: 27 additions & 0 deletions packages/react-native-host/cocoa/RNXTurboModuleAdapter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,26 @@
@implementation RNXTurboModuleAdapter {
#if USE_FABRIC
RCTTurboModuleManager *_turboModuleManager;
std::weak_ptr<facebook::react::CallInvoker> _jsInvoker;
#endif // USE_FABRIC
#if USE_RUNTIME_SCHEDULER
std::shared_ptr<facebook::react::RuntimeScheduler> _runtimeScheduler;
#endif // USE_RUNTIME_SCHEDULER
}

#if USE_FABRIC
- (instancetype)init
{
if (self = [super init]) {
[NSNotificationCenter.defaultCenter addObserver:self
selector:@selector(onRuntimeReady:)
name:@"RCTInstanceDidLoadBundle"
object:nil];
}
return self;
}
#endif // USE_FABRIC

- (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:
(RCTBridge *)bridge
{
Expand Down Expand Up @@ -90,6 +104,7 @@ - (Class)getModuleClassFromName:(char const *)name
jsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
{
#if __has_include(<react/nativemodule/defaults/DefaultTurboModules.h>) // >= 0.75
_jsInvoker = jsInvoker;
return facebook::react::DefaultTurboModules::getTurboModule(name, jsInvoker);
#else
return nullptr;
Expand Down Expand Up @@ -127,6 +142,18 @@ - (Class)getModuleClassFromName:(char const *)name
#endif // USE_RUNTIME_SCHEDULER
}

- (void)onRuntimeReady:(NSNotification *)note
{
if (auto jsInvoker = _jsInvoker.lock()) {
jsInvoker->invokeAsync([](facebook::jsi::Runtime &runtime) {
NSDictionary *userInfo = @{@"runtime": [NSValue valueWithPointer:&runtime]};
[NSNotificationCenter.defaultCenter postNotificationName:@"ReactAppRuntimeReady"
object:nil
userInfo:userInfo];
});
}
}

#endif // USE_FABRIC

@end
Loading