mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Implement new HostTargetMetadata fields (iOS) (#44933)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/44933 Resubmission of D58288489 (reverted due to C++ types in ObjC header). Changelog: [Internal] Reviewed By: motiz88 Differential Revision: D58522256 fbshipit-source-id: 5a413f1d5cca9555e309ab07e4de0e19ad2603cc
This commit is contained in:
committed by
Facebook GitHub Bot
parent
873ebc8055
commit
2cb04b4e2a
@@ -20,6 +20,7 @@
|
||||
#import <jsinspector-modern/ReactCdp.h>
|
||||
#import <optional>
|
||||
#import "RCTDevLoadingViewProtocol.h"
|
||||
#import "RCTInspectorUtils.h"
|
||||
#import "RCTJSThread.h"
|
||||
#import "RCTLog.h"
|
||||
#import "RCTModuleData.h"
|
||||
@@ -187,8 +188,14 @@ class RCTBridgeHostTargetDelegate : public facebook::react::jsinspector_modern::
|
||||
|
||||
facebook::react::jsinspector_modern::HostTargetMetadata getMetadata() override
|
||||
{
|
||||
auto metadata = [RCTInspectorUtils getHostMetadata];
|
||||
|
||||
return {
|
||||
.appIdentifier = [metadata.appIdentifier UTF8String],
|
||||
.deviceName = [metadata.deviceName UTF8String],
|
||||
.integrationName = "iOS Bridge (RCTBridge)",
|
||||
.platform = [metadata.platform UTF8String],
|
||||
.reactNativeVersion = [metadata.reactNativeVersion UTF8String],
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
// This is a subset of jsinspector_modern::HostTargetMetadata with ObjC types,
|
||||
// containing the nonnull members implemented by getHostMetadata.
|
||||
@interface CommonHostMetadata : NSObject
|
||||
|
||||
@property (nonatomic, strong) NSString *appIdentifier;
|
||||
@property (nonatomic, strong) NSString *deviceName;
|
||||
@property (nonatomic, strong) NSString *platform;
|
||||
@property (nonatomic, strong) NSString *reactNativeVersion;
|
||||
|
||||
@end
|
||||
|
||||
@interface RCTInspectorUtils : NSObject
|
||||
|
||||
+ (CommonHostMetadata *)getHostMetadata;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import "RCTInspectorUtils.h"
|
||||
|
||||
#import <React/RCTConstants.h>
|
||||
#import <React/RCTVersion.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@implementation CommonHostMetadata
|
||||
@end
|
||||
|
||||
@implementation RCTInspectorUtils
|
||||
|
||||
+ (CommonHostMetadata *)getHostMetadata
|
||||
{
|
||||
UIDevice *device = [UIDevice currentDevice];
|
||||
auto version = RCTGetReactNativeVersion();
|
||||
|
||||
CommonHostMetadata *metadata = [[CommonHostMetadata alloc] init];
|
||||
|
||||
metadata.appIdentifier = [[NSBundle mainBundle] bundleIdentifier];
|
||||
metadata.platform = RCTPlatformName;
|
||||
metadata.deviceName = [device name];
|
||||
metadata.reactNativeVersion =
|
||||
[NSString stringWithFormat:@"%i.%i.%i%@",
|
||||
[version[@"minor"] intValue],
|
||||
[version[@"major"] intValue],
|
||||
[version[@"patch"] intValue],
|
||||
[version[@"prerelease"] isKindOfClass:[NSNull class]]
|
||||
? @""
|
||||
: [@"-" stringByAppendingString:[version[@"prerelease"] stringValue]]];
|
||||
|
||||
return metadata;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -223,7 +223,21 @@ bool HostTargetController::decrementPauseOverlayCounter() {
|
||||
folly::dynamic hostMetadataToDynamic(const HostTargetMetadata& metadata) {
|
||||
folly::dynamic result = folly::dynamic::object;
|
||||
|
||||
result["integrationName"] = metadata.integrationName.value_or(nullptr);
|
||||
if (metadata.appIdentifier) {
|
||||
result["appIdentifier"] = metadata.appIdentifier.value();
|
||||
}
|
||||
if (metadata.deviceName) {
|
||||
result["deviceName"] = metadata.deviceName.value();
|
||||
}
|
||||
if (metadata.integrationName) {
|
||||
result["integrationName"] = metadata.integrationName.value();
|
||||
}
|
||||
if (metadata.platform) {
|
||||
result["platform"] = metadata.platform.value();
|
||||
}
|
||||
if (metadata.reactNativeVersion) {
|
||||
result["reactNativeVersion"] = metadata.reactNativeVersion.value();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,11 @@ class HostCommandSender;
|
||||
class HostTarget;
|
||||
|
||||
struct HostTargetMetadata {
|
||||
std::optional<std::string> appIdentifier;
|
||||
std::optional<std::string> deviceName;
|
||||
std::optional<std::string> integrationName;
|
||||
std::optional<std::string> platform;
|
||||
std::optional<std::string> reactNativeVersion;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -90,7 +94,8 @@ class HostTargetDelegate {
|
||||
virtual ~HostTargetDelegate();
|
||||
|
||||
/**
|
||||
* Returns a metadata object describing the host.
|
||||
* Returns a metadata object describing the host. This is called on an
|
||||
* initial response to @cdp ReactNativeApplication.enable.
|
||||
*/
|
||||
virtual HostTargetMetadata getMetadata() = 0;
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#import <React/RCTConvert.h>
|
||||
#import <React/RCTFabricSurface.h>
|
||||
#import <React/RCTInspectorDevServerHelper.h>
|
||||
#import <React/RCTInspectorUtils.h>
|
||||
#import <React/RCTJSThread.h>
|
||||
#import <React/RCTLog.h>
|
||||
#import <React/RCTMockDef.h>
|
||||
@@ -42,8 +43,14 @@ class RCTHostHostTargetDelegate : public facebook::react::jsinspector_modern::Ho
|
||||
|
||||
jsinspector_modern::HostTargetMetadata getMetadata() override
|
||||
{
|
||||
auto metadata = [RCTInspectorUtils getHostMetadata];
|
||||
|
||||
return {
|
||||
.appIdentifier = [metadata.appIdentifier UTF8String],
|
||||
.deviceName = [metadata.deviceName UTF8String],
|
||||
.integrationName = "iOS Bridgeless (RCTHost)",
|
||||
.platform = [metadata.platform UTF8String],
|
||||
.reactNativeVersion = [metadata.reactNativeVersion UTF8String],
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user