Scope RCTReloadNotification to one bridge

Summary:
At the moment, posting RCTReloadNotification in any circumstance causes all RCTBridge instances to reload. This change scopes the notification to the bridge for which it was intended.
Closes https://github.com/facebook/react-native/pull/8762

Differential Revision: D3831914

fbshipit-source-id: ff29574f574ecd1a403057ddd0458dea38f0136e
This commit is contained in:
Ben Roth 2016-09-07 17:24:23 -07:00 committed by Facebook Github Bot 2
parent efd8b10135
commit afde9da93d
7 changed files with 24 additions and 16 deletions

View File

@ -621,6 +621,11 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR
[_parentBridge reload]; [_parentBridge reload];
} }
- (void)requestReload
{
[_parentBridge requestReload];
}
- (Class)executorClass - (Class)executorClass
{ {
return _parentBridge.executorClass ?: [RCTJSCExecutor class]; return _parentBridge.executorClass ?: [RCTJSCExecutor class];

View File

@ -21,8 +21,9 @@
/** /**
* This notification triggers a reload of all bridges currently running. * 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. * This notification fires when the bridge starts loading the JS bundle.
@ -183,6 +184,11 @@ RCT_EXTERN NSString *RCTBridgeModuleNameForClass(Class bridgeModuleClass);
*/ */
- (void)reload; - (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. * Says whether bridge has started recieving calls from javascript.
*/ */

View File

@ -161,21 +161,15 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
{ {
RCTAssertMainQueue(); RCTAssertMainQueue();
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reload)
name:RCTReloadNotification
object:nil];
#if TARGET_IPHONE_SIMULATOR #if TARGET_IPHONE_SIMULATOR
RCTKeyCommands *commands = [RCTKeyCommands sharedInstance]; RCTKeyCommands *commands = [RCTKeyCommands sharedInstance];
// reload in current mode // reload in current mode
__weak typeof(self) weakSelf = self;
[commands registerKeyCommandWithInput:@"r" [commands registerKeyCommandWithInput:@"r"
modifierFlags:UIKeyModifierCommand modifierFlags:UIKeyModifierCommand
action:^(__unused UIKeyCommand *command) { action:^(__unused UIKeyCommand *command) {
[[NSNotificationCenter defaultCenter] postNotificationName:RCTReloadNotification [weakSelf requestReload];
object:nil
userInfo:nil];
}]; }];
#endif #endif
} }
@ -235,6 +229,12 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
}); });
} }
- (void)requestReload
{
[[NSNotificationCenter defaultCenter] postNotificationName:RCTReloadNotification object:self];
[self reload];
}
- (void)setUp - (void)setUp
{ {
RCT_PROFILE_BEGIN_EVENT(0, @"-[RCTBridge setUp]", nil); RCT_PROFILE_BEGIN_EVENT(0, @"-[RCTBridge setUp]", nil);

View File

@ -566,9 +566,7 @@ RCT_EXPORT_METHOD(show)
RCT_EXPORT_METHOD(reload) RCT_EXPORT_METHOD(reload)
{ {
[[NSNotificationCenter defaultCenter] postNotificationName:RCTReloadNotification [_bridge requestReload];
object:nil
userInfo:nil];
} }
- (void)setShakeToShow:(BOOL)shakeToShow - (void)setShakeToShow:(BOOL)shakeToShow

View File

@ -57,7 +57,7 @@ RCT_EXPORT_METHOD(reportFatalException:(NSString *)message
static NSUInteger reloadRetries = 0; static NSUInteger reloadRetries = 0;
if (!RCT_DEBUG && reloadRetries < _maxReloadAttempts) { if (!RCT_DEBUG && reloadRetries < _maxReloadAttempts) {
reloadRetries++; reloadRetries++;
[[NSNotificationCenter defaultCenter] postNotificationName:RCTReloadNotification object:nil]; [_bridge requestReload];
} else { } else {
NSString *description = [@"Unhandled JS Exception: " stringByAppendingString:message]; NSString *description = [@"Unhandled JS Exception: " stringByAppendingString:message];
NSDictionary *errorInfo = @{ NSLocalizedDescriptionKey: description, RCTJSStackTraceKey: stack }; NSDictionary *errorInfo = @{ NSLocalizedDescriptionKey: description, RCTJSStackTraceKey: stack };

View File

@ -450,7 +450,7 @@ RCT_EXPORT_METHOD(dismiss)
} }
- (void)reloadFromRedBoxWindow:(__unused RCTRedBoxWindow *)redBoxWindow { - (void)reloadFromRedBoxWindow:(__unused RCTRedBoxWindow *)redBoxWindow {
[[NSNotificationCenter defaultCenter] postNotificationName:RCTReloadNotification object:nil userInfo:nil]; [_bridge requestReload];
} }
@end @end

View File

@ -363,8 +363,7 @@ void RCTProfileUnhookModules(RCTBridge *bridge)
+ (void)reload + (void)reload
{ {
[[NSNotificationCenter defaultCenter] postNotificationName:RCTReloadNotification [RCTProfilingBridge() requestReload];
object:NULL];
} }
+ (void)toggle:(UIButton *)target + (void)toggle:(UIButton *)target