From 90a8e3012cc3d8d79a7fb3be8f2360393e9bd177 Mon Sep 17 00:00:00 2001 From: Christoph Nakazawa Date: Fri, 6 Sep 2019 03:46:45 -0700 Subject: [PATCH] Remove live reloading option from RN iOS Summary: See previous diff in this stack Reviewed By: motiz88 Differential Revision: D17156649 fbshipit-source-id: 12bdba248481258b9c6ca001472a41ca19fb4b6f --- .../FBReactNativeSpec-generated.mm | 7 - .../FBReactNativeSpec/FBReactNativeSpec.h | 1 - .../NativeModules/specs/NativeDevSettings.js | 1 - React/DevSupport/RCTDevMenu.m | 383 ++++++++++-------- React/Modules/RCTDevSettings.h | 9 +- React/Modules/RCTDevSettings.mm | 174 +++----- 6 files changed, 274 insertions(+), 301 deletions(-) diff --git a/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec-generated.mm b/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec-generated.mm index bf8bfae08a..e0ff2cfd60 100644 --- a/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec-generated.mm +++ b/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec-generated.mm @@ -793,10 +793,6 @@ namespace facebook { return static_cast(turboModule).invokeObjCMethod(rt, VoidKind, "setIsDebuggingRemotely", @selector(setIsDebuggingRemotely:), args, count); } - static facebook::jsi::Value __hostFunction_NativeDevSettingsSpecJSI_setLiveReloadEnabled(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { - return static_cast(turboModule).invokeObjCMethod(rt, VoidKind, "setLiveReloadEnabled", @selector(setLiveReloadEnabled:), args, count); - } - static facebook::jsi::Value __hostFunction_NativeDevSettingsSpecJSI_setProfilingEnabled(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { return static_cast(turboModule).invokeObjCMethod(rt, VoidKind, "setProfilingEnabled", @selector(setProfilingEnabled:), args, count); } @@ -822,9 +818,6 @@ namespace facebook { methodMap_["setIsDebuggingRemotely"] = MethodMetadata {1, __hostFunction_NativeDevSettingsSpecJSI_setIsDebuggingRemotely}; - methodMap_["setLiveReloadEnabled"] = MethodMetadata {1, __hostFunction_NativeDevSettingsSpecJSI_setLiveReloadEnabled}; - - methodMap_["setProfilingEnabled"] = MethodMetadata {1, __hostFunction_NativeDevSettingsSpecJSI_setProfilingEnabled}; diff --git a/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h b/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h index 7548c6ced5..9cc6942263 100644 --- a/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h +++ b/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h @@ -741,7 +741,6 @@ namespace facebook { - (void)reload; - (void)setHotLoadingEnabled:(BOOL)isHotLoadingEnabled; - (void)setIsDebuggingRemotely:(BOOL)isDebuggingRemotelyEnabled; -- (void)setLiveReloadEnabled:(BOOL)isLiveReloadEnabled; - (void)setProfilingEnabled:(BOOL)isProfilingEnabled; - (void)toggleElementInspector; - (void)setIsShakeToShowDevMenuEnabled:(BOOL)enabled; diff --git a/Libraries/NativeModules/specs/NativeDevSettings.js b/Libraries/NativeModules/specs/NativeDevSettings.js index ec0f9392e8..9741595601 100644 --- a/Libraries/NativeModules/specs/NativeDevSettings.js +++ b/Libraries/NativeModules/specs/NativeDevSettings.js @@ -17,7 +17,6 @@ export interface Spec extends TurboModule { +reload: () => void; +setHotLoadingEnabled: (isHotLoadingEnabled: boolean) => void; +setIsDebuggingRemotely: (isDebuggingRemotelyEnabled: boolean) => void; - +setLiveReloadEnabled: (isLiveReloadEnabled: boolean) => void; +setProfilingEnabled: (isProfilingEnabled: boolean) => void; +toggleElementInspector: () => void; diff --git a/React/DevSupport/RCTDevMenu.m b/React/DevSupport/RCTDevMenu.m index 5fdf10e662..d6ba1f6ee2 100644 --- a/React/DevSupport/RCTDevMenu.m +++ b/React/DevSupport/RCTDevMenu.m @@ -8,12 +8,12 @@ #import #import +#import +#import #import #import #import #import -#import -#import #if RCT_DEV_MENU @@ -34,14 +34,12 @@ NSString *const RCTShowDevMenuNotification = @"RCTShowDevMenuNotification"; @end -@implementation RCTDevMenuItem -{ +@implementation RCTDevMenuItem { RCTDevMenuItemTitleBlock _titleBlock; dispatch_block_t _handler; } -- (instancetype)initWithTitleBlock:(RCTDevMenuItemTitleBlock)titleBlock - handler:(dispatch_block_t)handler +- (instancetype)initWithTitleBlock:(RCTDevMenuItemTitleBlock)titleBlock handler:(dispatch_block_t)handler { if ((self = [super init])) { _titleBlock = [titleBlock copy]; @@ -50,17 +48,20 @@ NSString *const RCTShowDevMenuNotification = @"RCTShowDevMenuNotification"; return self; } -RCT_NOT_IMPLEMENTED(- (instancetype)init) +RCT_NOT_IMPLEMENTED(-(instancetype)init) -+ (instancetype)buttonItemWithTitleBlock:(NSString *(^)(void))titleBlock handler:(dispatch_block_t)handler ++ (instancetype)buttonItemWithTitleBlock:(NSString * (^)(void))titleBlock handler:(dispatch_block_t)handler { return [[self alloc] initWithTitleBlock:titleBlock handler:handler]; } -+ (instancetype)buttonItemWithTitle:(NSString *)title - handler:(dispatch_block_t)handler ++ (instancetype)buttonItemWithTitle:(NSString *)title handler:(dispatch_block_t)handler { - return [[self alloc] initWithTitleBlock:^NSString *{ return title; } handler:handler]; + return [[self alloc] + initWithTitleBlock:^NSString * { + return title; + } + handler:handler]; } - (void)callHandler @@ -80,14 +81,13 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init) @end -typedef void(^RCTDevMenuAlertActionHandler)(UIAlertAction *action); +typedef void (^RCTDevMenuAlertActionHandler)(UIAlertAction *action); @interface RCTDevMenu () @end -@implementation RCTDevMenu -{ +@implementation RCTDevMenu { UIAlertController *_actionSheet; NSMutableArray *_extraMenuItems; } @@ -155,7 +155,9 @@ RCT_EXPORT_MODULE() - (void)invalidate { _presentedItems = nil; - [_actionSheet dismissViewControllerAnimated:YES completion:^(void){}]; + [_actionSheet dismissViewControllerAnimated:YES + completion:^(void){ + }]; [[NSNotificationCenter defaultCenter] removeObserver:self]; } @@ -169,7 +171,9 @@ RCT_EXPORT_MODULE() - (void)toggle { if (_actionSheet) { - [_actionSheet dismissViewControllerAnimated:YES completion:^(void){}]; + [_actionSheet dismissViewControllerAnimated:YES + completion:^(void){ + }]; _actionSheet = nil; } else { [self show]; @@ -181,7 +185,7 @@ RCT_EXPORT_MODULE() return _actionSheet != nil; } -- (void)addItem:(NSString *)title handler:(void(^)(void))handler +- (void)addItem:(NSString *)title handler:(void (^)(void))handler { [self addItem:[RCTDevMenuItem buttonItemWithTitle:title handler:handler]]; } @@ -191,9 +195,11 @@ RCT_EXPORT_MODULE() [_extraMenuItems addObject:item]; } -- (void)setDefaultJSBundle { +- (void)setDefaultJSBundle +{ [[RCTBundleURLProvider sharedSettings] resetToDefaults]; - self->_bridge.bundleURL = [[RCTBundleURLProvider sharedSettings] jsBundleURLForFallbackResource:nil fallbackExtension:nil]; + self->_bridge.bundleURL = [[RCTBundleURLProvider sharedSettings] jsBundleURLForFallbackResource:nil + fallbackExtension:nil]; [self->_bridge reload]; } @@ -206,141 +212,182 @@ RCT_EXPORT_MODULE() __weak RCTDevSettings *devSettings = _bridge.devSettings; __weak RCTDevMenu *weakSelf = self; - [items addObject:[RCTDevMenuItem buttonItemWithTitle:@"Reload" handler:^{ - [bridge reload]; - }]]; + [items addObject:[RCTDevMenuItem buttonItemWithTitle:@"Reload" + handler:^{ + [bridge reload]; + }]]; if (!devSettings.isProfilingEnabled) { if (!devSettings.isRemoteDebuggingAvailable) { - [items addObject:[RCTDevMenuItem buttonItemWithTitle:@"Debugger Unavailable" handler:^{ - NSString *message = RCTTurboModuleEnabled() ? - @"Debugging is not currently supported when TurboModule is enabled." : - @"Include the RCTWebSocket library to enable JavaScript debugging."; - UIAlertController *alertController = [UIAlertController - alertControllerWithTitle:@"Debugger Unavailable" - message:message - preferredStyle:UIAlertControllerStyleAlert]; - __weak typeof(alertController) weakAlertController = alertController; - [alertController addAction: - [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(__unused UIAlertAction *action){ - [weakAlertController dismissViewControllerAnimated:YES completion:nil]; - }]]; - [RCTPresentedViewController() presentViewController:alertController animated:YES completion:NULL]; - }]]; + [items + addObject:[RCTDevMenuItem + buttonItemWithTitle:@"Debugger Unavailable" + handler:^{ + NSString *message = RCTTurboModuleEnabled() + ? @"Debugging is not currently supported when TurboModule is enabled." + : @"Include the RCTWebSocket library to enable JavaScript debugging."; + UIAlertController *alertController = + [UIAlertController alertControllerWithTitle:@"Debugger Unavailable" + message:message + preferredStyle:UIAlertControllerStyleAlert]; + __weak typeof(alertController) weakAlertController = alertController; + [alertController + addAction:[UIAlertAction actionWithTitle:@"OK" + style:UIAlertActionStyleDefault + handler:^(__unused UIAlertAction *action) { + [weakAlertController + dismissViewControllerAnimated:YES + completion:nil]; + }]]; + [RCTPresentedViewController() presentViewController:alertController + animated:YES + completion:NULL]; + }]]; } else { - [items addObject:[RCTDevMenuItem buttonItemWithTitleBlock:^NSString *{ - if (devSettings.isNuclideDebuggingAvailable) { - return devSettings.isDebuggingRemotely ? @"Stop Chrome Debugger" : @"Debug with Chrome"; - } else { - return devSettings.isDebuggingRemotely ? @"Stop Debugging" : @"Debug"; - } - } handler:^{ - devSettings.isDebuggingRemotely = !devSettings.isDebuggingRemotely; - }]]; + [items addObject:[RCTDevMenuItem + buttonItemWithTitleBlock:^NSString * { + if (devSettings.isNuclideDebuggingAvailable) { + return devSettings.isDebuggingRemotely ? @"Stop Chrome Debugger" : @"Debug with Chrome"; + } else { + return devSettings.isDebuggingRemotely ? @"Stop Debugging" : @"Debug"; + } + } + handler:^{ + devSettings.isDebuggingRemotely = !devSettings.isDebuggingRemotely; + }]]; } if (devSettings.isNuclideDebuggingAvailable && !devSettings.isDebuggingRemotely) { - [items addObject:[RCTDevMenuItem buttonItemWithTitle:@"Debug with Nuclide" handler:^{ - #if RCT_ENABLE_INSPECTOR && !TARGET_OS_UIKITFORMAC - [RCTInspectorDevServerHelper attachDebugger:@"ReactNative" withBundleURL:bridge.bundleURL withView: RCTPresentedViewController()]; - #endif - }]]; + [items addObject:[RCTDevMenuItem buttonItemWithTitle:@"Debug with Nuclide" + handler:^{ +#if RCT_ENABLE_INSPECTOR && !TARGET_OS_UIKITFORMAC + [RCTInspectorDevServerHelper + attachDebugger:@"ReactNative" + withBundleURL:bridge.bundleURL + withView:RCTPresentedViewController()]; +#endif + }]]; } } - [items addObject:[RCTDevMenuItem buttonItemWithTitleBlock:^NSString *{ - return devSettings.isElementInspectorShown ? @"Hide Inspector" : @"Show Inspector"; - } handler:^{ - [devSettings toggleElementInspector]; - }]]; + [items addObject:[RCTDevMenuItem + buttonItemWithTitleBlock:^NSString * { + return devSettings.isElementInspectorShown ? @"Hide Inspector" : @"Show Inspector"; + } + handler:^{ + [devSettings toggleElementInspector]; + }]]; if (devSettings.isHotLoadingAvailable) { - [items addObject:[RCTDevMenuItem buttonItemWithTitleBlock:^NSString *{ - // Previously known as "Hot Reloading". We won't use this term anymore. - return devSettings.isHotLoadingEnabled ? @"Disable Fast Refresh" : @"Enable Fast Refresh"; - } handler:^{ - devSettings.isHotLoadingEnabled = !devSettings.isHotLoadingEnabled; - }]]; + [items addObject:[RCTDevMenuItem + buttonItemWithTitleBlock:^NSString * { + // Previously known as "Hot Reloading". We won't use this term anymore. + return devSettings.isHotLoadingEnabled ? @"Disable Fast Refresh" : @"Enable Fast Refresh"; + } + handler:^{ + devSettings.isHotLoadingEnabled = !devSettings.isHotLoadingEnabled; + }]]; } if (devSettings.isLiveReloadAvailable) { - [items addObject:[RCTDevMenuItem buttonItemWithTitleBlock:^NSString *{ - return devSettings.isDebuggingRemotely - ? @"Systrace Unavailable" - : devSettings.isProfilingEnabled - ? @"Stop Systrace" - : @"Start Systrace"; - } handler:^{ - if (devSettings.isDebuggingRemotely) { - UIAlertController *alertController = [UIAlertController - alertControllerWithTitle:@"Systrace Unavailable" - message:@"Stop debugging to enable Systrace." - preferredStyle:UIAlertControllerStyleAlert]; - __weak typeof(alertController) weakAlertController = alertController; - [alertController addAction: - [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(__unused UIAlertAction *action){ - [weakAlertController dismissViewControllerAnimated:YES completion:nil]; - }]]; - [RCTPresentedViewController() presentViewController:alertController animated:YES completion:NULL]; - } else { - devSettings.isProfilingEnabled = !devSettings.isProfilingEnabled; - } - }]]; + [items addObject:[RCTDevMenuItem + buttonItemWithTitleBlock:^NSString * { + return devSettings.isDebuggingRemotely + ? @"Systrace Unavailable" + : devSettings.isProfilingEnabled ? @"Stop Systrace" : @"Start Systrace"; + } + handler:^{ + if (devSettings.isDebuggingRemotely) { + UIAlertController *alertController = + [UIAlertController alertControllerWithTitle:@"Systrace Unavailable" + message:@"Stop debugging to enable Systrace." + preferredStyle:UIAlertControllerStyleAlert]; + __weak typeof(alertController) weakAlertController = alertController; + [alertController + addAction:[UIAlertAction actionWithTitle:@"OK" + style:UIAlertActionStyleDefault + handler:^(__unused UIAlertAction *action) { + [weakAlertController + dismissViewControllerAnimated:YES + completion:nil]; + }]]; + [RCTPresentedViewController() presentViewController:alertController + animated:YES + completion:NULL]; + } else { + devSettings.isProfilingEnabled = !devSettings.isProfilingEnabled; + } + }]]; // "Live reload" which refreshes on every edit was removed in favor of "Fast Refresh". // While native code for "Live reload" is still there, please don't add the option back. // See D15958697 for more context. } - [items addObject:[RCTDevMenuItem buttonItemWithTitleBlock:^NSString *{ - return @"Configure Bundler"; - } handler:^{ - UIAlertController * alertController = [UIAlertController alertControllerWithTitle: @"Configure Bundler" - message: @"Provide a custom bundler address, port, and entrypoint." - preferredStyle:UIAlertControllerStyleAlert]; - [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) { - textField.placeholder = @"0.0.0.0"; - }]; - [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) { - textField.placeholder = @"8081"; - }]; - [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) { - textField.placeholder = @"index"; - }]; - [alertController addAction:[UIAlertAction actionWithTitle:@"Apply Changes" style:UIAlertActionStyleDefault handler:^(__unused UIAlertAction *action) { - NSArray * textfields = alertController.textFields; - UITextField * ipTextField = textfields[0]; - UITextField * portTextField = textfields[1]; - UITextField * bundleRootTextField = textfields[2]; - NSString * bundleRoot = bundleRootTextField.text; - if(ipTextField.text.length == 0 && portTextField.text.length == 0) { - [weakSelf setDefaultJSBundle]; - return; - } - NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; - formatter.numberStyle = NSNumberFormatterDecimalStyle; - NSNumber *portNumber = [formatter numberFromString:portTextField.text]; - if (portNumber == nil) { - portNumber = [NSNumber numberWithInt: RCT_METRO_PORT]; - } - [RCTBundleURLProvider sharedSettings].jsLocation = [NSString stringWithFormat:@"%@:%d", - ipTextField.text, portNumber.intValue]; - __strong RCTBridge *strongBridge = bridge; - if (strongBridge) { - NSURL *bundleURL = bundleRoot.length - ? [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:bundleRoot fallbackResource:nil] - : [strongBridge.delegate sourceURLForBridge:strongBridge]; - strongBridge.bundleURL = bundleURL; - [strongBridge reload]; - } - }]]; - [alertController addAction:[UIAlertAction actionWithTitle:@"Reset to Default" style:UIAlertActionStyleDefault handler:^(__unused UIAlertAction *action) { - [weakSelf setDefaultJSBundle]; - }]]; - [alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(__unused UIAlertAction *action) { - return; - }]]; - [RCTPresentedViewController() presentViewController:alertController animated:YES completion:NULL]; - }]]; + [items + addObject:[RCTDevMenuItem + buttonItemWithTitleBlock:^NSString * { + return @"Configure Bundler"; + } + handler:^{ + UIAlertController *alertController = [UIAlertController + alertControllerWithTitle:@"Configure Bundler" + message:@"Provide a custom bundler address, port, and entrypoint." + preferredStyle:UIAlertControllerStyleAlert]; + [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) { + textField.placeholder = @"0.0.0.0"; + }]; + [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) { + textField.placeholder = @"8081"; + }]; + [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) { + textField.placeholder = @"index"; + }]; + [alertController + addAction:[UIAlertAction + actionWithTitle:@"Apply Changes" + style:UIAlertActionStyleDefault + handler:^(__unused UIAlertAction *action) { + NSArray *textfields = alertController.textFields; + UITextField *ipTextField = textfields[0]; + UITextField *portTextField = textfields[1]; + UITextField *bundleRootTextField = textfields[2]; + NSString *bundleRoot = bundleRootTextField.text; + if (ipTextField.text.length == 0 && portTextField.text.length == 0) { + [weakSelf setDefaultJSBundle]; + return; + } + NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; + formatter.numberStyle = NSNumberFormatterDecimalStyle; + NSNumber *portNumber = + [formatter numberFromString:portTextField.text]; + if (portNumber == nil) { + portNumber = [NSNumber numberWithInt:RCT_METRO_PORT]; + } + [RCTBundleURLProvider sharedSettings].jsLocation = [NSString + stringWithFormat:@"%@:%d", ipTextField.text, portNumber.intValue]; + __strong RCTBridge *strongBridge = bridge; + if (strongBridge) { + NSURL *bundleURL = bundleRoot.length + ? [[RCTBundleURLProvider sharedSettings] + jsBundleURLForBundleRoot:bundleRoot + fallbackResource:nil] + : [strongBridge.delegate sourceURLForBridge:strongBridge]; + strongBridge.bundleURL = bundleURL; + [strongBridge reload]; + } + }]]; + [alertController addAction:[UIAlertAction actionWithTitle:@"Reset to Default" + style:UIAlertActionStyleDefault + handler:^(__unused UIAlertAction *action) { + [weakSelf setDefaultJSBundle]; + }]]; + [alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" + style:UIAlertActionStyleCancel + handler:^(__unused UIAlertAction *action) { + return; + }]]; + [RCTPresentedViewController() presentViewController:alertController animated:YES completion:NULL]; + }]]; [items addObjectsFromArray:_extraMenuItems]; return items; @@ -353,12 +400,13 @@ RCT_EXPORT_METHOD(show) } NSString *bridgeDescription = _bridge.bridgeDescription; - NSString *description = bridgeDescription.length > 0 - ? [NSString stringWithFormat:@"Running %@", bridgeDescription] - : nil; + NSString *description = + bridgeDescription.length > 0 ? [NSString stringWithFormat:@"Running %@", bridgeDescription] : nil; // On larger devices we don't have an anchor point for the action sheet - UIAlertControllerStyle style = [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone ? UIAlertControllerStyleActionSheet : UIAlertControllerStyleAlert; + UIAlertControllerStyle style = [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone + ? UIAlertControllerStyleActionSheet + : UIAlertControllerStyleAlert; _actionSheet = [UIAlertController alertControllerWithTitle:@"React Native Debug Menu" message:description preferredStyle:style]; @@ -391,7 +439,8 @@ RCT_EXPORT_METHOD(show) #pragma mark - deprecated methods and properties -#define WARN_DEPRECATED_DEV_MENU_EXPORT() RCTLogWarn(@"Using deprecated method %s, use RCTDevSettings instead", __func__) +#define WARN_DEPRECATED_DEV_MENU_EXPORT() \ + RCTLogWarn(@"Using deprecated method %s, use RCTDevSettings instead", __func__) - (void)setShakeToShow:(BOOL)shakeToShow { @@ -409,13 +458,13 @@ RCT_EXPORT_METHOD(reload) [_bridge reload]; } -RCT_EXPORT_METHOD(debugRemotely:(BOOL)enableDebug) +RCT_EXPORT_METHOD(debugRemotely : (BOOL)enableDebug) { WARN_DEPRECATED_DEV_MENU_EXPORT(); _bridge.devSettings.isDebuggingRemotely = enableDebug; } -RCT_EXPORT_METHOD(setProfilingEnabled:(BOOL)enabled) +RCT_EXPORT_METHOD(setProfilingEnabled : (BOOL)enabled) { WARN_DEPRECATED_DEV_MENU_EXPORT(); _bridge.devSettings.isProfilingEnabled = enabled; @@ -426,18 +475,7 @@ RCT_EXPORT_METHOD(setProfilingEnabled:(BOOL)enabled) return _bridge.devSettings.isProfilingEnabled; } -RCT_EXPORT_METHOD(setLiveReloadEnabled:(BOOL)enabled) -{ - WARN_DEPRECATED_DEV_MENU_EXPORT(); - _bridge.devSettings.isLiveReloadEnabled = enabled; -} - -- (BOOL)liveReloadEnabled -{ - return _bridge.devSettings.isLiveReloadEnabled; -} - -RCT_EXPORT_METHOD(setHotLoadingEnabled:(BOOL)enabled) +RCT_EXPORT_METHOD(setHotLoadingEnabled : (BOOL)enabled) { WARN_DEPRECATED_DEV_MENU_EXPORT(); _bridge.devSettings.isHotLoadingEnabled = enabled; @@ -454,26 +492,45 @@ RCT_EXPORT_METHOD(setHotLoadingEnabled:(BOOL)enabled) @implementation RCTDevMenu -- (void)show {} -- (void)reload {} -- (void)addItem:(NSString *)title handler:(dispatch_block_t)handler {} -- (void)addItem:(RCTDevMenu *)item {} -- (BOOL)isActionSheetShown { return NO; } -+ (NSString *)moduleName { return @""; } +- (void)show +{ +} +- (void)reload +{ +} +- (void)addItem:(NSString *)title handler:(dispatch_block_t)handler +{ +} +- (void)addItem:(RCTDevMenu *)item +{ +} +- (BOOL)isActionSheetShown +{ + return NO; +} ++ (NSString *)moduleName +{ + return @""; +} @end @implementation RCTDevMenuItem -+ (instancetype)buttonItemWithTitle:(NSString *)title handler:(void(^)(void))handler {return nil;} -+ (instancetype)buttonItemWithTitleBlock:(NSString * (^)(void))titleBlock - handler:(void(^)(void))handler {return nil;} ++ (instancetype)buttonItemWithTitle:(NSString *)title handler:(void (^)(void))handler +{ + return nil; +} ++ (instancetype)buttonItemWithTitleBlock:(NSString * (^)(void))titleBlock handler:(void (^)(void))handler +{ + return nil; +} @end #endif -@implementation RCTBridge (RCTDevMenu) +@implementation RCTBridge (RCTDevMenu) - (RCTDevMenu *)devMenu { diff --git a/React/Modules/RCTDevSettings.h b/React/Modules/RCTDevSettings.h index 246df19e47..76265915f8 100644 --- a/React/Modules/RCTDevSettings.h +++ b/React/Modules/RCTDevSettings.h @@ -55,12 +55,6 @@ */ @property (nonatomic, assign, setter=setProfilingEnabled:) BOOL isProfilingEnabled; -/** - * Whether automatic polling for JS code changes is enabled. Only applicable when - * running the app from a server. - */ -@property (nonatomic, assign, setter=setLiveReloadEnabled:) BOOL isLiveReloadEnabled; - /** * Whether hot loading is enabled. */ @@ -87,7 +81,8 @@ @property (nonatomic, assign) BOOL isPerfMonitorShown; #if RCT_DEV_MENU -- (void)addHandler:(id)handler forPackagerMethod:(NSString *)name __deprecated_msg("Use RCTPackagerConnection directly instead"); +- (void)addHandler:(id)handler + forPackagerMethod:(NSString *)name __deprecated_msg("Use RCTPackagerConnection directly instead"); #endif @end diff --git a/React/Modules/RCTDevSettings.mm b/React/Modules/RCTDevSettings.mm index d0f929685f..d72002a258 100644 --- a/React/Modules/RCTDevSettings.mm +++ b/React/Modules/RCTDevSettings.mm @@ -18,9 +18,6 @@ static NSString *const kRCTDevSettingProfilingEnabled = @"profilingEnabled"; static NSString *const kRCTDevSettingHotLoadingEnabled = @"hotLoadingEnabled"; -// This option is no longer exposed in the dev menu UI. -// It was renamed in D15958697 so it doesn't get stuck with no way to turn it off: -static NSString *const kRCTDevSettingLiveReloadEnabled = @"liveReloadEnabled_LEGACY"; static NSString *const kRCTDevSettingIsInspectorShown = @"showInspector"; static NSString *const kRCTDevSettingIsDebuggingRemotely = @"isDebuggingRemotely"; static NSString *const kRCTDevSettingExecutorOverrideClass = @"executor-override"; @@ -100,10 +97,7 @@ static NSString *const kRCTDevSettingsUserDefaultsKey = @"RCTDevMenu"; @end -@interface RCTDevSettings () -{ - NSURLSessionDataTask *_liveReloadUpdateTask; - NSURL *_liveReloadURL; +@interface RCTDevSettings () { BOOL _isJSLoaded; #if ENABLE_PACKAGER_CONNECTION RCTHandlerToken _reloadToken; @@ -130,10 +124,11 @@ RCT_EXPORT_MODULE() { // default behavior is to use NSUserDefaults NSDictionary *defaultValues = @{ - kRCTDevSettingShakeToShowDevMenu: @YES, - kRCTDevSettingHotLoadingEnabled: @YES, + kRCTDevSettingShakeToShowDevMenu : @YES, + kRCTDevSettingHotLoadingEnabled : @YES, }; - RCTDevSettingsUserDefaultsDataSource *dataSource = [[RCTDevSettingsUserDefaultsDataSource alloc] initWithDefaultValues:defaultValues]; + RCTDevSettingsUserDefaultsDataSource *dataSource = + [[RCTDevSettingsUserDefaultsDataSource alloc] initWithDefaultValues:defaultValues]; return [self initWithDataSource:dataSource]; } @@ -162,16 +157,15 @@ RCT_EXPORT_MODULE() #if ENABLE_PACKAGER_CONNECTION RCTBridge *__weak weakBridge = bridge; - _reloadToken = - [[RCTPackagerConnection sharedPackagerConnection] - addNotificationHandler:^(id params) { - if (params != (id)kCFNull && [params[@"debug"] boolValue]) { - weakBridge.executorClass = objc_lookUpClass("RCTWebSocketExecutor"); - } - [weakBridge reload]; - } - queue:dispatch_get_main_queue() - forMethod:@"reload"]; + _reloadToken = [[RCTPackagerConnection sharedPackagerConnection] + addNotificationHandler:^(id params) { + if (params != (id)kCFNull && [params[@"debug"] boolValue]) { + weakBridge.executorClass = objc_lookUpClass("RCTWebSocketExecutor"); + } + [weakBridge reload]; + } + queue:dispatch_get_main_queue() + forMethod:@"reload"]; #endif #if RCT_ENABLE_INSPECTOR && !TARGET_OS_UIKITFORMAC @@ -181,9 +175,11 @@ RCT_EXPORT_MODULE() // relinquishes control of the main thread, so only queue on the JS thread // after the current main thread operation is done. dispatch_async(dispatch_get_main_queue(), ^{ - [bridge dispatchBlock:^{ - [RCTInspectorDevServerHelper connectWithBundleURL:bridge.bundleURL]; - } queue:RCTJSThread]; + [bridge + dispatchBlock:^{ + [RCTInspectorDevServerHelper connectWithBundleURL:bridge.bundleURL]; + } + queue:RCTJSThread]; }); #endif } @@ -195,7 +191,6 @@ RCT_EXPORT_MODULE() - (void)invalidate { - [_liveReloadUpdateTask cancel]; #if ENABLE_PACKAGER_CONNECTION [[RCTPackagerConnection sharedPackagerConnection] removeHandler:_reloadToken]; #endif @@ -235,17 +230,12 @@ RCT_EXPORT_MODULE() return _bridge.bundleURL && !_bridge.bundleURL.fileURL; // Only works when running from server } -- (BOOL)isLiveReloadAvailable -{ - return (_liveReloadURL != nil); -} - RCT_EXPORT_METHOD(reload) { [_bridge reload]; } -RCT_EXPORT_METHOD(setIsShakeToShowDevMenuEnabled:(BOOL)enabled) +RCT_EXPORT_METHOD(setIsShakeToShowDevMenuEnabled : (BOOL)enabled) { [self _updateSettingWithValue:@(enabled) forKey:kRCTDevSettingShakeToShowDevMenu]; } @@ -255,7 +245,7 @@ RCT_EXPORT_METHOD(setIsShakeToShowDevMenuEnabled:(BOOL)enabled) return [[self settingForKey:kRCTDevSettingShakeToShowDevMenu] boolValue]; } -RCT_EXPORT_METHOD(setIsDebuggingRemotely:(BOOL)enabled) +RCT_EXPORT_METHOD(setIsDebuggingRemotely : (BOOL)enabled) { [self _updateSettingWithValue:@(enabled) forKey:kRCTDevSettingIsDebuggingRemotely]; [self _remoteDebugSettingDidChange]; @@ -279,7 +269,7 @@ RCT_EXPORT_METHOD(setIsDebuggingRemotely:(BOOL)enabled) } } -RCT_EXPORT_METHOD(setProfilingEnabled:(BOOL)enabled) +RCT_EXPORT_METHOD(setProfilingEnabled : (BOOL)enabled) { [self _updateSettingWithValue:@(enabled) forKey:kRCTDevSettingProfilingEnabled]; [self _profilingSettingDidChange]; @@ -293,7 +283,7 @@ RCT_EXPORT_METHOD(setProfilingEnabled:(BOOL)enabled) - (void)_profilingSettingDidChange { BOOL enabled = self.isProfilingEnabled; - if (_liveReloadURL && enabled != RCTProfileIsProfiling()) { + if (self.isHotLoadingAvailable && enabled != RCTProfileIsProfiling()) { if (enabled) { [_bridge startProfiling]; } else { @@ -304,47 +294,19 @@ RCT_EXPORT_METHOD(setProfilingEnabled:(BOOL)enabled) } } -RCT_EXPORT_METHOD(setLiveReloadEnabled:(BOOL)enabled) -{ - [self _updateSettingWithValue:@(enabled) forKey:kRCTDevSettingLiveReloadEnabled]; - [self _liveReloadSettingDidChange]; -} - -- (BOOL)isLiveReloadEnabled -{ - return [[self settingForKey:kRCTDevSettingLiveReloadEnabled] boolValue]; -} - -- (void)_liveReloadSettingDidChange -{ - BOOL liveReloadEnabled = (self.isLiveReloadAvailable && self.isLiveReloadEnabled); - if (liveReloadEnabled) { - [self _pollForLiveReload]; - } else { - [_liveReloadUpdateTask cancel]; - _liveReloadUpdateTask = nil; - } -} - -RCT_EXPORT_METHOD(setHotLoadingEnabled:(BOOL)enabled) +RCT_EXPORT_METHOD(setHotLoadingEnabled : (BOOL)enabled) { if (self.isHotLoadingEnabled != enabled) { [self _updateSettingWithValue:@(enabled) forKey:kRCTDevSettingHotLoadingEnabled]; if (_isJSLoaded) { - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wdeprecated-declarations" +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" if (enabled) { - [_bridge enqueueJSCall:@"HMRClient" - method:@"enable" - args:@[] - completion:NULL]; + [_bridge enqueueJSCall:@"HMRClient" method:@"enable" args:@[] completion:NULL]; } else { - [_bridge enqueueJSCall:@"HMRClient" - method:@"disable" - args:@[] - completion:NULL]; + [_bridge enqueueJSCall:@"HMRClient" method:@"disable" args:@[] completion:NULL]; } - #pragma clang diagnostic pop +#pragma clang diagnostic pop } } } @@ -386,13 +348,11 @@ RCT_EXPORT_METHOD(toggleElementInspector) { _executorClass = executorClass; if (_bridge.executorClass != executorClass) { - // TODO (6929129): we can remove this special case test once we have better // support for custom executors in the dev menu. But right now this is // needed to prevent overriding a custom executor with the default if a // custom executor has been set directly on the bridge - if (executorClass == Nil && - _bridge.executorClass != objc_lookUpClass("RCTWebSocketExecutor")) { + if (executorClass == Nil && _bridge.executorClass != objc_lookUpClass("RCTWebSocketExecutor")) { return; } @@ -420,45 +380,10 @@ RCT_EXPORT_METHOD(toggleElementInspector) */ - (void)_synchronizeAllSettings { - [self _liveReloadSettingDidChange]; [self _remoteDebugSettingDidChange]; [self _profilingSettingDidChange]; } -- (void)_pollForLiveReload -{ - if (!_isJSLoaded || ![[self settingForKey:kRCTDevSettingLiveReloadEnabled] boolValue] || !_liveReloadURL) { - return; - } - - if (_liveReloadUpdateTask) { - return; - } - - __weak RCTDevSettings *weakSelf = self; - _liveReloadUpdateTask = [[NSURLSession sharedSession] dataTaskWithURL:_liveReloadURL completionHandler: - ^(__unused NSData *data, NSURLResponse *response, NSError *error) { - - dispatch_async(dispatch_get_main_queue(), ^{ - __strong RCTDevSettings *strongSelf = weakSelf; - if (strongSelf && [[strongSelf settingForKey:kRCTDevSettingLiveReloadEnabled] boolValue]) { - NSHTTPURLResponse *HTTPResponse = (NSHTTPURLResponse *)response; - if (!error && HTTPResponse.statusCode == 205) { - [strongSelf reload]; - } else { - if (error.code != NSURLErrorCancelled) { - strongSelf->_liveReloadUpdateTask = nil; - [strongSelf _pollForLiveReload]; - } - } - } - }); - - }]; - - [_liveReloadUpdateTask resume]; -} - - (void)jsLoaded:(NSNotification *)notification { if (notification.userInfo[@"bridge"] != _bridge) { @@ -466,16 +391,6 @@ RCT_EXPORT_METHOD(toggleElementInspector) } _isJSLoaded = YES; - - // Check if live reloading is available - NSURL *scriptURL = _bridge.bundleURL; - if (![scriptURL isFileURL]) { - // Live reloading is disabled when running from bundled JS file - _liveReloadURL = [[NSURL alloc] initWithString:@"/onchange" relativeToURL:scriptURL]; - } else { - _liveReloadURL = nil; - } - dispatch_async(dispatch_get_main_queue(), ^{ // update state again after the bridge has finished loading [self _synchronizeAllSettings]; @@ -496,13 +411,28 @@ RCT_EXPORT_METHOD(toggleElementInspector) @implementation RCTDevSettings -- (instancetype)initWithDataSource:(id)dataSource { return [super init]; } -- (BOOL)isHotLoadingAvailable { return NO; } -- (BOOL)isLiveReloadAvailable { return NO; } -- (BOOL)isRemoteDebuggingAvailable { return NO; } -- (id)settingForKey:(NSString *)key { return nil; } -- (void)reload {} -- (void)toggleElementInspector {} +- (instancetype)initWithDataSource:(id)dataSource +{ + return [super init]; +} +- (BOOL)isHotLoadingAvailable +{ + return NO; +} +- (BOOL)isRemoteDebuggingAvailable +{ + return NO; +} +- (id)settingForKey:(NSString *)key +{ + return nil; +} +- (void)reload +{ +} +- (void)toggleElementInspector +{ +} @end