Skip to content

Commit 14914bd

Browse files
huntiefacebook-github-bot
authored andcommitted
Implement new HostTargetMetadata fields (iOS) (#44893)
Summary: Pull Request resolved: #44893 Adds the following debugger metadata fields (sent over the `ReactNativeApplication.metadataUpdated` CDP event), and implements these on iOS (Bridge and Bridgeless). - `appIdentifier` - `deviceName` - `platform` - `reactNativeVersion` Changelog: [Internal] Reviewed By: robhogan Differential Revision: D58288489 fbshipit-source-id: 7105ad3b70d409bcd98b232154ebd6b7c827fb2b
1 parent aced407 commit 14914bd

File tree

6 files changed

+89
-1
lines changed

6 files changed

+89
-1
lines changed

packages/react-native/React/Base/RCTBridge.mm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#import <jsinspector-modern/ReactCdp.h>
2121
#import <optional>
2222
#import "RCTDevLoadingViewProtocol.h"
23+
#import "RCTInspectorUtils.h"
2324
#import "RCTJSThread.h"
2425
#import "RCTLog.h"
2526
#import "RCTModuleData.h"
@@ -199,8 +200,14 @@ void RCTUIManagerSetDispatchAccessibilityManagerInitOntoMain(BOOL enabled)
199200

200201
facebook::react::jsinspector_modern::HostTargetMetadata getMetadata() override
201202
{
203+
auto metadata = [RCTInspectorUtils getHostMetadata];
204+
202205
return {
206+
.appIdentifier = metadata.appIdentifier,
207+
.deviceName = metadata.deviceName,
203208
.integrationName = "iOS Bridge (RCTBridge)",
209+
.platform = metadata.platform,
210+
.reactNativeVersion = metadata.reactNativeVersion,
204211
};
205212
}
206213

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#import <Foundation/Foundation.h>
9+
10+
#import <string>
11+
12+
struct CommonHostMetadata {
13+
std::string appIdentifier;
14+
std::string deviceName;
15+
std::string platform;
16+
std::string reactNativeVersion;
17+
};
18+
19+
@interface RCTInspectorUtils : NSObject
20+
21+
+ (CommonHostMetadata)getHostMetadata;
22+
23+
@end
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#import "RCTInspectorUtils.h"
9+
10+
#import <React/RCTConstants.h>
11+
#import <React/RCTVersion.h>
12+
#import <UIKit/UIKit.h>
13+
14+
@implementation RCTInspectorUtils
15+
16+
+ (CommonHostMetadata)getHostMetadata
17+
{
18+
UIDevice *device = [UIDevice currentDevice];
19+
20+
NSString *appIdentifier = [[NSBundle mainBundle] bundleIdentifier];
21+
NSString *platform = RCTPlatformName;
22+
NSString *deviceName = [device name];
23+
24+
auto version = RCTGetReactNativeVersion();
25+
NSString *reactNativeVersion =
26+
[NSString stringWithFormat:@"%i.%i.%i%@",
27+
[version[@"minor"] intValue],
28+
[version[@"major"] intValue],
29+
[version[@"patch"] intValue],
30+
[version[@"prerelease"] isKindOfClass:[NSNull class]]
31+
? @""
32+
: [@"-" stringByAppendingString:[version[@"prerelease"] stringValue]]];
33+
34+
return {
35+
.appIdentifier = [appIdentifier UTF8String],
36+
.platform = [platform UTF8String],
37+
.deviceName = [deviceName UTF8String],
38+
.reactNativeVersion = [reactNativeVersion UTF8String],
39+
};
40+
}
41+
42+
@end

packages/react-native/ReactCommon/jsinspector-modern/HostTarget.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,11 @@ bool HostTargetController::decrementPauseOverlayCounter() {
223223
folly::dynamic hostMetadataToDynamic(const HostTargetMetadata& metadata) {
224224
folly::dynamic result = folly::dynamic::object;
225225

226+
result["appIdentifier"] = metadata.appIdentifier.value_or(nullptr);
227+
result["deviceName"] = metadata.deviceName.value_or(nullptr);
226228
result["integrationName"] = metadata.integrationName.value_or(nullptr);
229+
result["platform"] = metadata.platform.value_or(nullptr);
230+
result["reactNativeVersion"] = metadata.reactNativeVersion.value_or(nullptr);
227231

228232
return result;
229233
}

packages/react-native/ReactCommon/jsinspector-modern/HostTarget.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ class HostCommandSender;
3737
class HostTarget;
3838

3939
struct HostTargetMetadata {
40+
std::optional<std::string> appIdentifier;
41+
std::optional<std::string> deviceName;
4042
std::optional<std::string> integrationName;
43+
std::optional<std::string> platform;
44+
std::optional<std::string> reactNativeVersion;
4145
};
4246

4347
/**
@@ -90,7 +94,8 @@ class HostTargetDelegate {
9094
virtual ~HostTargetDelegate();
9195

9296
/**
93-
* Returns a metadata object describing the host.
97+
* Returns a metadata object describing the host. This is called on an
98+
* initial response to @cdp ReactNativeApplication.enable.
9499
*/
95100
virtual HostTargetMetadata getMetadata() = 0;
96101

packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTHost.mm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#import <React/RCTConvert.h>
1414
#import <React/RCTFabricSurface.h>
1515
#import <React/RCTInspectorDevServerHelper.h>
16+
#import <React/RCTInspectorUtils.h>
1617
#import <React/RCTJSThread.h>
1718
#import <React/RCTLog.h>
1819
#import <React/RCTMockDef.h>
@@ -42,8 +43,14 @@ @interface RCTHost () <RCTReloadListener, RCTInstanceDelegate>
4243

4344
jsinspector_modern::HostTargetMetadata getMetadata() override
4445
{
46+
auto metadata = [RCTInspectorUtils getHostMetadata];
47+
4548
return {
49+
.appIdentifier = metadata.appIdentifier,
50+
.deviceName = metadata.deviceName,
4651
.integrationName = "iOS Bridgeless (RCTHost)",
52+
.platform = metadata.platform,
53+
.reactNativeVersion = metadata.reactNativeVersion,
4754
};
4855
}
4956

0 commit comments

Comments
 (0)