Skip to content

Commit 673ab7c

Browse files
CopilotSaadnajmi
andcommitted
Restore original iOS code, only modify macOS section
Co-authored-by: Saadnajmi <[email protected]>
1 parent e0824a4 commit 673ab7c

File tree

1 file changed

+50
-39
lines changed

1 file changed

+50
-39
lines changed

packages/react-native/React/CoreModules/RCTDevMenu.mm

Lines changed: 50 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ + (void)initialize
127127
{
128128
#if !TARGET_OS_OSX // [macOS]
129129
// We're swizzling here because it's poor form to override methods in a category,
130-
RCTOriginalUIWindowMotionEndedWithEventImp = (MotionEndedWithEventImpType)RCTSwapInstanceMethods(
131-
[UIWindow class], @selector(motionEnded:withEvent:), @selector(RCT_motionEnded:withEvent:)); // [macOS]
130+
RCTOriginalUIWindowMotionEndedWithEventImp = (MotionEndedWithEventImpType) RCTSwapInstanceMethods([UIWindow class], @selector(motionEnded:withEvent:), @selector(RCT_motionEnded:withEvent:)); // [macOS]
132131
#endif // [macOS]
133132
}
134133

@@ -342,37 +341,6 @@ - (void)setDefaultJSBundle
342341
return @"Configure Bundler";
343342
}
344343
handler:^{
345-
// Shared callback for applying bundler configuration
346-
void (^applyBundlerConfig)(NSString *, NSString *, NSString *) =
347-
^(NSString *ipAddress, NSString *port, NSString *bundleRoot) {
348-
// If both IP and port are empty, reset to default
349-
if (ipAddress.length == 0 && port.length == 0) {
350-
[weakSelf setDefaultJSBundle];
351-
return;
352-
}
353-
354-
// Parse and validate port number
355-
NSNumberFormatter *formatter = [NSNumberFormatter new];
356-
formatter.numberStyle = NSNumberFormatterDecimalStyle;
357-
NSNumber *portNumber = [formatter numberFromString:port];
358-
if (portNumber == nil) {
359-
portNumber = [NSNumber numberWithInt:RCT_METRO_PORT];
360-
}
361-
362-
// Set the bundler location
363-
[RCTBundleURLProvider sharedSettings].jsLocation =
364-
[NSString stringWithFormat:@"%@:%d", ipAddress, portNumber.intValue];
365-
366-
if (bundleRoot.length == 0) {
367-
[bundleManager resetBundleURL];
368-
} else {
369-
bundleManager.bundleURL =
370-
[[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:bundleRoot];
371-
}
372-
373-
RCTTriggerReloadCommandListeners(@"Dev menu - apply changes");
374-
};
375-
376344
#if !TARGET_OS_OSX // [macOS]
377345
UIAlertController *alertController = [UIAlertController
378346
alertControllerWithTitle:@"Configure Bundler"
@@ -396,8 +364,28 @@ - (void)setDefaultJSBundle
396364
UITextField *ipTextField = textfields[0];
397365
UITextField *portTextField = textfields[1];
398366
UITextField *bundleRootTextField = textfields[2];
399-
applyBundlerConfig(
400-
ipTextField.text, portTextField.text, bundleRootTextField.text);
367+
NSString *bundleRoot = bundleRootTextField.text;
368+
if (ipTextField.text.length == 0 && portTextField.text.length == 0) {
369+
[weakSelf setDefaultJSBundle];
370+
return;
371+
}
372+
NSNumberFormatter *formatter = [NSNumberFormatter new];
373+
formatter.numberStyle = NSNumberFormatterDecimalStyle;
374+
NSNumber *portNumber =
375+
[formatter numberFromString:portTextField.text];
376+
if (portNumber == nil) {
377+
portNumber = [NSNumber numberWithInt:RCT_METRO_PORT];
378+
}
379+
[RCTBundleURLProvider sharedSettings].jsLocation = [NSString
380+
stringWithFormat:@"%@:%d", ipTextField.text, portNumber.intValue];
381+
if (bundleRoot.length == 0) {
382+
[bundleManager resetBundleURL];
383+
} else {
384+
bundleManager.bundleURL = [[RCTBundleURLProvider sharedSettings]
385+
jsBundleURLForBundleRoot:bundleRoot];
386+
}
387+
388+
RCTTriggerReloadCommandListeners(@"Dev menu - apply changes");
401389
}]];
402390
[alertController addAction:[UIAlertAction actionWithTitle:@"Reset to Default"
403391
style:UIAlertActionStyleDefault
@@ -449,10 +437,33 @@ - (void)setDefaultJSBundle
449437
completionHandler:^(NSModalResponse response) {
450438
if (response == NSAlertFirstButtonReturn) {
451439
// Apply Changes
452-
applyBundlerConfig(
453-
ipTextField.stringValue,
454-
portTextField.stringValue,
455-
entrypointTextField.stringValue);
440+
NSString *ipAddress = ipTextField.stringValue;
441+
NSString *port = portTextField.stringValue;
442+
NSString *bundleRoot = entrypointTextField.stringValue;
443+
444+
if (ipAddress.length == 0 && port.length == 0) {
445+
[weakSelf setDefaultJSBundle];
446+
return;
447+
}
448+
449+
NSNumberFormatter *formatter = [NSNumberFormatter new];
450+
formatter.numberStyle = NSNumberFormatterDecimalStyle;
451+
NSNumber *portNumber = [formatter numberFromString:port];
452+
if (portNumber == nil) {
453+
portNumber = [NSNumber numberWithInt:RCT_METRO_PORT];
454+
}
455+
456+
[RCTBundleURLProvider sharedSettings].jsLocation =
457+
[NSString stringWithFormat:@"%@:%d", ipAddress, portNumber.intValue];
458+
459+
if (bundleRoot.length == 0) {
460+
[bundleManager resetBundleURL];
461+
} else {
462+
bundleManager.bundleURL = [[RCTBundleURLProvider sharedSettings]
463+
jsBundleURLForBundleRoot:bundleRoot];
464+
}
465+
466+
RCTTriggerReloadCommandListeners(@"Dev menu - apply changes");
456467
} else if (response == NSAlertSecondButtonReturn) {
457468
// Reset to Default
458469
[weakSelf setDefaultJSBundle];

0 commit comments

Comments
 (0)