Skip to content

Commit

Permalink
Move kRCTPlatformName to RCTConstants.h (#39141)
Browse files Browse the repository at this point in the history
Summary:
This PR is another one made with the intent to reduce the number of diffs between React Native and React Native macOS.

In f7219ec#diff-d091f6636e07dc62dd7d892489355707c43923ac15056fd2eb59d9a297d576a6 , we introduced `kRCTPlatformName`, which had already been in React Native macOS for a while (since we ifdef to either "ios" or "macos" in a number of places). This change moves the string up to a common header (dropping the "k" prefix) so we can refactor other strings that currently have a hardcoded "platform=ios" inside them.

## Changelog:

[IOS] [CHANGED] - Add RCTPlatformName to RCTConstants.h

Pull Request resolved: #39141

Test Plan: CI should pass

Reviewed By: NickGerleman

Differential Revision: D48656197

Pulled By: lunaleaps

fbshipit-source-id: b9ff08e2591d7553a1a452795f36d4405ddaa5b1
  • Loading branch information
Saadnajmi authored and facebook-github-bot committed Aug 29, 2023
1 parent 0c25f19 commit 046ae12
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 14 deletions.
4 changes: 2 additions & 2 deletions packages/react-native/React/Base/RCTBundleURLProvider.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#import "RCTBundleURLProvider.h"

#import "RCTConstants.h"
#import "RCTConvert.h"
#import "RCTDefines.h"
#import "RCTLog.h"
Expand All @@ -22,7 +23,6 @@ void RCTBundleURLProviderAllowPackagerServerAccess(BOOL allowed)
kRCTAllowPackagerAccess = allowed;
}
#endif
static NSString *const kRCTPlatformName = @"ios";
static NSString *const kRCTPackagerSchemeKey = @"RCT_packager_scheme";
static NSString *const kRCTJsLocationKey = @"RCT_jsLocation";
static NSString *const kRCTEnableDevKey = @"RCT_enableDev";
Expand Down Expand Up @@ -307,7 +307,7 @@ + (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot
NSString *path = [NSString stringWithFormat:@"/%@.bundle", bundleRoot];
BOOL lazy = enableDev;
NSArray<NSURLQueryItem *> *queryItems = @[
[[NSURLQueryItem alloc] initWithName:@"platform" value:kRCTPlatformName],
[[NSURLQueryItem alloc] initWithName:@"platform" value:RCTPlatformName],
[[NSURLQueryItem alloc] initWithName:@"dev" value:enableDev ? @"true" : @"false"],
[[NSURLQueryItem alloc] initWithName:@"lazy" value:lazy ? @"true" : @"false"],
[[NSURLQueryItem alloc] initWithName:@"minify" value:enableMinification ? @"true" : @"false"],
Expand Down
2 changes: 2 additions & 0 deletions packages/react-native/React/Base/RCTConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#import <React/RCTDefines.h>

RCT_EXTERN NSString *const RCTPlatformName;

RCT_EXTERN NSString *const RCTUserInterfaceStyleDidChangeNotification;
RCT_EXTERN NSString *const RCTUserInterfaceStyleDidChangeNotificationTraitCollectionKey;

Expand Down
2 changes: 2 additions & 0 deletions packages/react-native/React/Base/RCTConstants.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#import "RCTConstants.h"

NSString *const RCTPlatformName = @"ios";

NSString *const RCTUserInterfaceStyleDidChangeNotification = @"RCTUserInterfaceStyleDidChangeNotification";
NSString *const RCTUserInterfaceStyleDidChangeNotificationTraitCollectionKey = @"traitCollection";

Expand Down
7 changes: 4 additions & 3 deletions packages/react-native/React/CoreModules/RCTDevSettings.mm
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,10 @@ - (void)setupHMRClientWithBundleURL:(NSURL *)bundleURL
NSNumber *const port = urlComponents.port;
NSString *const scheme = urlComponents.scheme;
BOOL isHotLoadingEnabled = self.isHotLoadingEnabled;
[self.callableJSModules invokeModule:@"HMRClient"
method:@"setup"
withArgs:@[ @"ios", path, host, RCTNullIfNil(port), @(isHotLoadingEnabled), scheme ]];
[self.callableJSModules
invokeModule:@"HMRClient"
method:@"setup"
withArgs:@[ RCTPlatformName, path, host, RCTNullIfNil(port), @(isHotLoadingEnabled), scheme ]];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#import <React/RCTAssert.h>
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTConstants.h>
#import <React/RCTConvert.h>
#import <React/RCTDefines.h>
#import <React/RCTLog.h>
Expand Down Expand Up @@ -100,7 +101,7 @@ - (instancetype)init
components.scheme = scheme;
components.port = serverPort ? @(serverPort.integerValue) : @(kRCTBundleURLProviderDefaultPort);
components.path = @"/message";
components.queryItems = @[ [NSURLQueryItem queryItemWithName:@"role" value:@"ios"] ];
components.queryItems = @[ [NSURLQueryItem queryItemWithName:@"role" value:RCTPlatformName] ];
static dispatch_queue_t queue;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Expand Down
6 changes: 4 additions & 2 deletions packages/rn-tester/RCTTest/RCTTestRunner.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#import <React/RCTAssert.h>
#import <React/RCTBridge+Private.h>
#import <React/RCTConstants.h>
#import <React/RCTDevSettings.h>
#import <React/RCTLog.h>
#import <React/RCTRootView.h>
Expand Down Expand Up @@ -87,8 +88,9 @@ - (instancetype)initWithApp:(NSString *)app
- (NSURL *)defaultScriptURL
{
if (getenv("CI_USE_PACKAGER") || _useBundler) {
return [NSURL
URLWithString:[NSString stringWithFormat:@"http://localhost:8081/%@.bundle?platform=ios&dev=true", _appPath]];
return [NSURL URLWithString:[NSString stringWithFormat:@"http://localhost:8081/%@.bundle?platform=%@&dev=true",
_appPath,
RCTPlatformName]];
} else {
return [[NSBundle bundleForClass:[RCTBridge class]] URLForResource:@"main" withExtension:@"jsbundle"];
}
Expand Down
6 changes: 4 additions & 2 deletions packages/rn-tester/RNTesterIntegrationTests/RCTLoggingTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#import <React/RCTAssert.h>
#import <React/RCTBridge.h>
#import <React/RCTConstants.h>
#import <React/RCTLog.h>

// Time to wait for an expected log statement to show before failing the test
Expand All @@ -32,8 +33,9 @@ - (void)setUp
NSURL *scriptURL;
if (getenv("CI_USE_PACKAGER")) {
NSString *app = @"IntegrationTests/IntegrationTestsApp";
scriptURL =
[NSURL URLWithString:[NSString stringWithFormat:@"http://localhost:8081/%@.bundle?platform=ios&dev=true", app]];
scriptURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://localhost:8081/%@.bundle?platform=%@&dev=true",
app,
RCTPlatformName]];
} else {
scriptURL = [[NSBundle bundleForClass:[RCTBridge class]] URLForResource:@"main" withExtension:@"jsbundle"];
}
Expand Down
11 changes: 7 additions & 4 deletions packages/rn-tester/RNTesterUnitTests/RCTBundleURLProviderTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#import <XCTest/XCTest.h>

#import <React/RCTBundleURLProvider.h>
#import <React/RCTConstants.h>
#import <React/RCTUtils.h>

#import "OCMock/OCMock.h"
Expand All @@ -26,8 +27,9 @@
URLWithString:
[NSString
stringWithFormat:
@"http://localhost:8081/%@.bundle?platform=ios&dev=true&lazy=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.apple.dt.xctest.tool",
testFile]];
@"http://localhost:8081/%@.bundle?platform=%@&dev=true&lazy=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.apple.dt.xctest.tool",
testFile,
RCTPlatformName]];
}

static NSURL *ipBundleURL(void)
Expand All @@ -36,8 +38,9 @@
URLWithString:
[NSString
stringWithFormat:
@"http://192.168.1.1:8081/%@.bundle?platform=ios&dev=true&lazy=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.apple.dt.xctest.tool",
testFile]];
@"http://192.168.1.1:8081/%@.bundle?platform=%@&dev=true&lazy=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.apple.dt.xctest.tool",
testFile,
RCTPlatformName]];
}

@implementation NSBundle (RCTBundleURLProviderTests)
Expand Down

0 comments on commit 046ae12

Please sign in to comment.