diff --git a/React/Base/RCTBatchedBridge.m b/React/Base/RCTBatchedBridge.m index 867626233ab..0fe7c5210ff 100644 --- a/React/Base/RCTBatchedBridge.m +++ b/React/Base/RCTBatchedBridge.m @@ -621,6 +621,11 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR [_parentBridge reload]; } +- (void)requestReload +{ + [_parentBridge requestReload]; +} + - (Class)executorClass { return _parentBridge.executorClass ?: [RCTJSCExecutor class]; diff --git a/React/Base/RCTBridge.h b/React/Base/RCTBridge.h index 944997666ce..b87821c9b36 100644 --- a/React/Base/RCTBridge.h +++ b/React/Base/RCTBridge.h @@ -21,8 +21,9 @@ /** * This notification triggers a reload of all bridges currently running. + * Deprecated, use RCTBridge::requestReload instead. */ -RCT_EXTERN NSString *const RCTReloadNotification; +RCT_EXTERN NSString *const RCTReloadNotification DEPRECATED_ATTRIBUTE; /** * This notification fires when the bridge starts loading the JS bundle. @@ -183,6 +184,11 @@ RCT_EXTERN NSString *RCTBridgeModuleNameForClass(Class bridgeModuleClass); */ - (void)reload; +/** + * Inform the bridge, and anything subscribing to it, that it should reload. + */ +- (void)requestReload; + /** * Says whether bridge has started recieving calls from javascript. */ diff --git a/React/Base/RCTBridge.m b/React/Base/RCTBridge.m index 16086005bbd..5743229906c 100644 --- a/React/Base/RCTBridge.m +++ b/React/Base/RCTBridge.m @@ -161,21 +161,15 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init) { RCTAssertMainQueue(); - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(reload) - name:RCTReloadNotification - object:nil]; - #if TARGET_IPHONE_SIMULATOR RCTKeyCommands *commands = [RCTKeyCommands sharedInstance]; // reload in current mode + __weak typeof(self) weakSelf = self; [commands registerKeyCommandWithInput:@"r" modifierFlags:UIKeyModifierCommand action:^(__unused UIKeyCommand *command) { - [[NSNotificationCenter defaultCenter] postNotificationName:RCTReloadNotification - object:nil - userInfo:nil]; + [weakSelf requestReload]; }]; #endif } @@ -235,6 +229,12 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init) }); } +- (void)requestReload +{ + [[NSNotificationCenter defaultCenter] postNotificationName:RCTReloadNotification object:self]; + [self reload]; +} + - (void)setUp { RCT_PROFILE_BEGIN_EVENT(0, @"-[RCTBridge setUp]", nil); diff --git a/React/Modules/RCTDevMenu.m b/React/Modules/RCTDevMenu.m index 66181785b1a..b6ad245aeee 100644 --- a/React/Modules/RCTDevMenu.m +++ b/React/Modules/RCTDevMenu.m @@ -566,9 +566,7 @@ RCT_EXPORT_METHOD(show) RCT_EXPORT_METHOD(reload) { - [[NSNotificationCenter defaultCenter] postNotificationName:RCTReloadNotification - object:nil - userInfo:nil]; + [_bridge requestReload]; } - (void)setShakeToShow:(BOOL)shakeToShow diff --git a/React/Modules/RCTExceptionsManager.m b/React/Modules/RCTExceptionsManager.m index 791c163f16d..5e7b08b7198 100644 --- a/React/Modules/RCTExceptionsManager.m +++ b/React/Modules/RCTExceptionsManager.m @@ -57,7 +57,7 @@ RCT_EXPORT_METHOD(reportFatalException:(NSString *)message static NSUInteger reloadRetries = 0; if (!RCT_DEBUG && reloadRetries < _maxReloadAttempts) { reloadRetries++; - [[NSNotificationCenter defaultCenter] postNotificationName:RCTReloadNotification object:nil]; + [_bridge requestReload]; } else { NSString *description = [@"Unhandled JS Exception: " stringByAppendingString:message]; NSDictionary *errorInfo = @{ NSLocalizedDescriptionKey: description, RCTJSStackTraceKey: stack }; diff --git a/React/Modules/RCTRedBox.m b/React/Modules/RCTRedBox.m index 1a60451eb06..f5434b5ef34 100644 --- a/React/Modules/RCTRedBox.m +++ b/React/Modules/RCTRedBox.m @@ -450,7 +450,7 @@ RCT_EXPORT_METHOD(dismiss) } - (void)reloadFromRedBoxWindow:(__unused RCTRedBoxWindow *)redBoxWindow { - [[NSNotificationCenter defaultCenter] postNotificationName:RCTReloadNotification object:nil userInfo:nil]; + [_bridge requestReload]; } @end diff --git a/React/Profiler/RCTProfile.m b/React/Profiler/RCTProfile.m index 7a9edf8be82..8026d62d139 100644 --- a/React/Profiler/RCTProfile.m +++ b/React/Profiler/RCTProfile.m @@ -363,8 +363,7 @@ void RCTProfileUnhookModules(RCTBridge *bridge) + (void)reload { - [[NSNotificationCenter defaultCenter] postNotificationName:RCTReloadNotification - object:NULL]; + [RCTProfilingBridge() requestReload]; } + (void)toggle:(UIButton *)target