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
53 changes: 35 additions & 18 deletions common/AppRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,50 @@
#if __has_include(<jsi/jsi.h>)
#include <jsi/jsi.h>

using facebook::jsi::Array;
using facebook::jsi::Runtime;
using facebook::jsi::String;

std::vector<std::string> ReactTestApp::GetAppKeys(Runtime &runtime)
namespace
{
std::vector<std::string> result;

constexpr char kFbBatchedBridgeId[] = "__fbBatchedBridge";
constexpr char kRNAppRegistryId[] = "RN$AppRegistry";

Array GetRegisteredAppKeys(Runtime &runtime)
{
auto global = runtime.global();
if (global.hasProperty(runtime, kRNAppRegistryId)) { // >= 0.73
// const appKeys = RN$AppRegistry.getAppKeys();
auto registry = global.getProperty(runtime, kRNAppRegistryId);
if (registry.isObject()) {
auto getAppKeys = std::move(registry).asObject(runtime).getPropertyAsFunction(
runtime, "getAppKeys");
return getAppKeys.call(runtime, nullptr, 0).asObject(runtime).asArray(runtime);
}
} else if (global.hasProperty(runtime, kFbBatchedBridgeId)) { // < 0.73
// const appRegistry = __fbBatchedBridge.getCallableModule("AppRegistry");
auto fbBatchedBridge = global.getPropertyAsObject(runtime, kFbBatchedBridgeId);
auto getCallableModule =
fbBatchedBridge.getPropertyAsFunction(runtime, "getCallableModule");
auto appRegistry =
getCallableModule.callWithThis(runtime, fbBatchedBridge, "AppRegistry")
.asObject(runtime);

// const appKeys = appRegistry.getAppKeys();
auto getAppKeys = appRegistry.getPropertyAsFunction(runtime, "getAppKeys");
return getAppKeys.callWithThis(runtime, appRegistry).asObject(runtime).asArray(runtime);
}

auto global = runtime.global();
if (!global.hasProperty(runtime, kFbBatchedBridgeId)) {
return result;
return Array(runtime, 0);
}
} // namespace

try {
// const appRegistry = __fbBatchedBridge.getCallableModule("AppRegistry");
auto fbBatchedBridge = global.getPropertyAsObject(runtime, kFbBatchedBridgeId);
auto getCallableModule =
fbBatchedBridge.getPropertyAsFunction(runtime, "getCallableModule");
auto appRegistry = getCallableModule.callWithThis(runtime, fbBatchedBridge, "AppRegistry")
.asObject(runtime);

// const appKeys = appRegistry.getAppKeys();
auto getAppKeys = appRegistry.getPropertyAsFunction(runtime, "getAppKeys");
auto appKeys =
getAppKeys.callWithThis(runtime, appRegistry).asObject(runtime).asArray(runtime);
std::vector<std::string> ReactTestApp::GetAppKeys(Runtime &runtime)
{
std::vector<std::string> result;

try {
auto appKeys = GetRegisteredAppKeys(runtime);
auto length = appKeys.length(runtime);
result.reserve(length);

Expand Down
8 changes: 4 additions & 4 deletions example/ios/ExampleTests/DevSupportTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ @implementation DevSupportTests

- (void)testDevSupportIsLinked
{
XCTAssertNotNil(ReactTestAppDidInitializeNotification);
XCTAssertNotNil(ReactTestAppWillInitializeReactNativeNotification);
XCTAssertNotNil(ReactTestAppDidInitializeReactNativeNotification);
XCTAssertNotNil(ReactTestAppSceneDidOpenURLNotification);
XCTAssertNotNil(ReactAppDidFinishLaunchingNotification);
XCTAssertNotNil(ReactAppWillInitializeReactNativeNotification);
XCTAssertNotNil(ReactAppDidInitializeReactNativeNotification);
XCTAssertNotNil(ReactAppSceneDidOpenURLNotification);
}

@end
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,7 @@ PODS:
- React-logger (= 0.78.2)
- React-perflogger (= 0.78.2)
- React-utils (= 0.78.2)
- ReactNativeHost (0.5.5):
- ReactNativeHost (0.5.8):
- DoubleConversion
- glog
- RCT-Folly (= 2024.11.18.00)
Expand Down Expand Up @@ -1814,7 +1814,7 @@ SPEC CHECKSUMS:
ReactAppDependencyProvider: 4893bde33952f997a323eb1a1ee87a72764018ff
ReactCodegen: a99d9f9129c83cdd5c58dea8826d1b82ec528b93
ReactCommon: 5008bd981a06fe63176ef815f092685ffee8f7eb
ReactNativeHost: 8bf59aebad1f1cdd377510f12172b4b9cdbb5161
ReactNativeHost: 9f5d82f9edc73c42ed09e949a19d2ef9cf5ac064
ReactTestApp-DevSupport: 2386e7c22084f8a550cfadcc0bde140c7dc328a1
ReactTestApp-Resources: 1bd9ff10e4c24f2ad87101a32023721ae923bccf
RNWWebStorage: cf4c36a41d7d31734b1a3424c70cb555e86801be
Expand Down
4 changes: 2 additions & 2 deletions example/macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1483,7 +1483,7 @@ PODS:
- React-logger (= 0.78.3)
- React-perflogger (= 0.78.3)
- React-utils (= 0.78.3)
- ReactNativeHost (0.5.5):
- ReactNativeHost (0.5.8):
- DoubleConversion
- glog
- RCT-Folly (= 2024.11.18.00)
Expand Down Expand Up @@ -1814,7 +1814,7 @@ SPEC CHECKSUMS:
ReactAppDependencyProvider: a12262458b50521ba56afb93f4cc875732f9d643
ReactCodegen: 191e4a5cb0241651f2fcf21d79729c6465f0f905
ReactCommon: 0f22e3dd34a8215b8482778898f6e1e95572c498
ReactNativeHost: 8bf59aebad1f1cdd377510f12172b4b9cdbb5161
ReactNativeHost: 9f5d82f9edc73c42ed09e949a19d2ef9cf5ac064
ReactTestApp-DevSupport: 2386e7c22084f8a550cfadcc0bde140c7dc328a1
ReactTestApp-Resources: 86136e1efe3aa7201759371c03dea3df77079b42
RNWWebStorage: cf4c36a41d7d31734b1a3424c70cb555e86801be
Expand Down
4 changes: 2 additions & 2 deletions example/visionos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1536,7 +1536,7 @@ PODS:
- React-logger (= 0.78.0)
- React-perflogger (= 0.78.0)
- React-utils (= 0.78.0)
- ReactNativeHost (0.5.5):
- ReactNativeHost (0.5.8):
- DoubleConversion
- glog
- RCT-Folly (= 2024.11.18.00)
Expand Down Expand Up @@ -1880,7 +1880,7 @@ SPEC CHECKSUMS:
ReactAppDependencyProvider: b0dbc9d44b4e45e2b2468df4a2f49fb51806224f
ReactCodegen: 4d719f75b156783b8fdf07fe4091a7f38bc52967
ReactCommon: a690d72c5df9a63d64a2444d5aad695c37554ea7
ReactNativeHost: 8bf59aebad1f1cdd377510f12172b4b9cdbb5161
ReactNativeHost: 9f5d82f9edc73c42ed09e949a19d2ef9cf5ac064
ReactTestApp-DevSupport: 2386e7c22084f8a550cfadcc0bde140c7dc328a1
ReactTestApp-Resources: 2ad57492ef72ab9b2c6f6e89ea198cc1999ca20b
RNWWebStorage: cf4c36a41d7d31734b1a3424c70cb555e86801be
Expand Down
2 changes: 1 addition & 1 deletion ios/ReactTestApp/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

defer {
NotificationCenter.default.post(
name: .ReactTestAppDidInitialize,
name: .ReactAppDidFinishLaunching,
object: nil
)
}
Expand Down
5 changes: 0 additions & 5 deletions ios/ReactTestApp/AppRegistryModule.h
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
#import <Foundation/Foundation.h>

#import <React/RCTBridgeModule.h>

@interface RTAAppRegistryModule : NSObject <RCTBridgeModule>
@end
48 changes: 15 additions & 33 deletions ios/ReactTestApp/AppRegistryModule.mm
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,26 @@ @interface RCTCxxBridge : RCTBridge
- (void)invokeAsync:(std::function<void()> &&)func;
@end

@implementation RTAAppRegistryModule

RCT_EXPORT_MODULE();

+ (BOOL)requiresMainQueueSetup
void RTAPostDidRegisterAppsNotification(NSValue *value)
{
return YES;
}
auto runtime = static_cast<Runtime *>([value pointerValue]);
auto appKeys = ReactTestApp::GetAppKeys(*runtime);
if (appKeys.empty()) {
return;
}

- (instancetype)init
{
if (self = [super init]) {
[NSNotificationCenter.defaultCenter addObserver:self
selector:@selector(javascriptDidLoadNotification:)
name:RCTJavaScriptDidLoadNotification
object:nil];
NSMutableArray *array = [NSMutableArray arrayWithCapacity:appKeys.size()];
for (const auto &appKey : appKeys) {
[array addObject:[NSString stringWithUTF8String:appKey.c_str()]];
}
return self;

[NSNotificationCenter.defaultCenter postNotificationName:ReactAppDidRegisterAppsNotification
object:nil
userInfo:@{@"appKeys": [array copy]}];
}

- (void)javascriptDidLoadNotification:(NSNotification *)note
void RTAPostDidRegisterAppsNotificationWithBridge(id bridge)
{
id bridge = note.userInfo[@"bridge"];
if (![bridge isKindOfClass:[RCTCxxBridge class]] ||
![bridge respondsToSelector:@selector(runtime)] ||
![bridge respondsToSelector:@selector(invokeAsync:)]) {
Expand All @@ -50,21 +47,6 @@ - (void)javascriptDidLoadNotification:(NSNotification *)note
return;
}

auto appKeys = ReactTestApp::GetAppKeys(*runtime);
if (appKeys.empty()) {
return;
}

NSMutableArray *array = [NSMutableArray arrayWithCapacity:appKeys.size()];
for (const auto &appKey : appKeys) {
[array addObject:[NSString stringWithUTF8String:appKey.c_str()]];
}

[NSNotificationCenter.defaultCenter
postNotificationName:ReactTestAppDidRegisterAppsNotification
object:nil
userInfo:@{@"appKeys": [array copy]}];
RTAPostDidRegisterAppsNotification([NSValue valueWithPointer:runtime]);
}];
}

@end
2 changes: 1 addition & 1 deletion ios/ReactTestApp/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ final class ContentViewController: UITableViewController {
let components = manifest.components ?? []
if components.isEmpty {
NotificationCenter.default.addObserver(
forName: .ReactTestAppDidRegisterApps,
forName: .ReactAppDidRegisterApps,
object: nil,
queue: .main,
using: { [weak self] note in
Expand Down
28 changes: 22 additions & 6 deletions ios/ReactTestApp/Public/ReactTestApp-DevSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,30 @@

NS_ASSUME_NONNULL_BEGIN

extern NSNotificationName const ReactTestAppDidInitializeNotification;
OBJC_EXTERN NSNotificationName const ReactAppDidFinishLaunchingNotification;

extern NSNotificationName const ReactTestAppWillInitializeReactNativeNotification;
extern NSNotificationName const ReactTestAppDidInitializeReactNativeNotification;
extern NSNotificationName const ReactTestAppDidRegisterAppsNotification;
OBJC_EXTERN NSNotificationName const ReactAppWillInitializeReactNativeNotification;
OBJC_EXTERN NSNotificationName const ReactAppDidInitializeReactNativeNotification;

extern NSNotificationName const ReactTestAppSceneDidOpenURLNotification;
OBJC_EXTERN NSNotificationName const ReactAppRuntimeReady;
OBJC_EXTERN NSNotificationName const ReactAppDidRegisterAppsNotification;

extern NSNotificationName const ReactInstanceDidLoadBundle;
OBJC_EXTERN NSNotificationName const ReactAppSceneDidOpenURLNotification;

OBJC_EXTERN NSNotificationName const ReactTestAppDidInitializeNotification
__deprecated_msg("Use 'ReactAppDidFinishLaunchingNotification' instead");
OBJC_EXTERN NSNotificationName const ReactTestAppWillInitializeReactNativeNotification
__deprecated_msg("Use 'ReactAppWillInitializeReactNativeNotification' instead");
OBJC_EXTERN NSNotificationName const ReactTestAppDidInitializeReactNativeNotification
__deprecated_msg("Use 'ReactAppDidInitializeReactNativeNotification' instead");
OBJC_EXTERN NSNotificationName const ReactTestAppDidRegisterAppsNotification
__deprecated_msg("Use 'ReactAppDidRegisterAppsNotification' instead");
OBJC_EXTERN NSNotificationName const ReactTestAppSceneDidOpenURLNotification
__deprecated_msg("Use 'ReactAppSceneDidOpenURLNotification' instead");

OBJC_EXTERN NSNotificationName const ReactInstanceDidLoadBundle;

OBJC_EXTERN void RTAPostDidRegisterAppsNotification(NSValue *runtime);
OBJC_EXTERN void RTAPostDidRegisterAppsNotificationWithBridge(id bridge);

NS_ASSUME_NONNULL_END
30 changes: 25 additions & 5 deletions ios/ReactTestApp/ReactInstance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,33 @@ final class ReactInstance: NSObject, RNXHostConfig {
override init() {
super.init()

let defaultNotificationCenter = NotificationCenter.default

// Bridged
NotificationCenter.default.addObserver(
defaultNotificationCenter.addObserver(
self,
selector: #selector(onJavaScriptLoaded(_:)),
name: .RCTJavaScriptDidLoad,
object: nil
)

// Bridgeless
NotificationCenter.default.addObserver(
defaultNotificationCenter.addObserver(
self,
selector: #selector(onJavaScriptLoaded(_:)),
name: .ReactInstanceDidLoadBundle,
object: nil
)

defaultNotificationCenter.addObserver(
self,
selector: #selector(onRuntimeReady(_:)),
name: .ReactAppRuntimeReady,
object: nil
)

#if os(iOS)
NotificationCenter.default.addObserver(
defaultNotificationCenter.addObserver(
self,
selector: #selector(onRemoteBundleURLReceived(_:)),
name: .didReceiveRemoteBundleURL,
Expand Down Expand Up @@ -90,15 +99,15 @@ final class ReactInstance: NSObject, RNXHostConfig {
self.bundleRoot = bundleRoot

NotificationCenter.default.post(
name: .ReactTestAppWillInitializeReactNative,
name: .ReactAppWillInitializeReactNative,
object: nil
)

let reactNativeHost = ReactNativeHost(self)
host = reactNativeHost

NotificationCenter.default.post(
name: .ReactTestAppDidInitializeReactNative,
name: .ReactAppDidInitializeReactNative,
object: reactNativeHost
)

Expand Down Expand Up @@ -209,6 +218,10 @@ final class ReactInstance: NSObject, RNXHostConfig {
})
#endif
}

if let bridge = notification.userInfo?["bridge"] {
RTAPostDidRegisterAppsNotificationWithBridge(bridge)
}
}

@objc
Expand All @@ -220,6 +233,13 @@ final class ReactInstance: NSObject, RNXHostConfig {
urlComponents.queryItems = [URLQueryItem(name: "platform", value: "ios")]
remoteBundleURL = urlComponents.url
}

@objc
private func onRuntimeReady(_ notification: Notification) {
if let runtime = notification.userInfo?["runtime"] as? NSValue {
RTAPostDidRegisterAppsNotification(runtime)
}
}
}

#if canImport(UIKit)
Expand Down
27 changes: 20 additions & 7 deletions ios/ReactTestApp/ReactTestApp-DevSupport.m
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
#import <Foundation/Foundation.h>

NSNotificationName const ReactTestAppDidInitializeNotification =
@"ReactTestAppDidInitializeNotification";
NSNotificationName const ReactAppDidFinishLaunchingNotification =
@"ReactAppDidFinishLaunchNotification";

NSNotificationName const ReactAppWillInitializeReactNativeNotification =
@"ReactAppWillInitializeReactNativeNotification";
NSNotificationName const ReactAppDidInitializeReactNativeNotification =
@"ReactAppDidInitializeReactNativeNotification";

NSNotificationName const ReactAppRuntimeReady = @"ReactAppRuntimeReady";
NSNotificationName const ReactAppDidRegisterAppsNotification =
@"ReactAppDidRegisterAppsNotification";

NSNotificationName const ReactAppSceneDidOpenURLNotification =
@"ReactAppSceneDidOpenURLNotification";

NSNotificationName const ReactTestAppDidInitializeNotification =
ReactAppDidFinishLaunchingNotification;
NSNotificationName const ReactTestAppWillInitializeReactNativeNotification =
@"ReactTestAppWillInitializeReactNativeNotification";
ReactAppWillInitializeReactNativeNotification;
NSNotificationName const ReactTestAppDidInitializeReactNativeNotification =
@"ReactTestAppDidInitializeReactNativeNotification";
ReactAppDidInitializeReactNativeNotification;
NSNotificationName const ReactTestAppDidRegisterAppsNotification =
@"ReactTestAppDidRegisterAppsNotification";

ReactAppDidRegisterAppsNotification;
NSNotificationName const ReactTestAppSceneDidOpenURLNotification =
@"ReactTestAppSceneDidOpenURLNotification";
ReactAppSceneDidOpenURLNotification;

// https://github.com/facebook/react-native/blob/v0.73.4/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm#L448
NSNotificationName const ReactInstanceDidLoadBundle = @"RCTInstanceDidLoadBundle";
2 changes: 1 addition & 1 deletion ios/ReactTestApp/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
}

NotificationCenter.default.post(
name: .ReactTestAppSceneDidOpenURL,
name: .ReactAppSceneDidOpenURL,
object: [
"scene": scene,
"URLContexts": URLContexts,
Expand Down
Loading
Loading