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:
parent
efd8b10135
commit
afde9da93d
|
@ -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];
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 };
|
||||
|
|
|
@ -450,7 +450,7 @@ RCT_EXPORT_METHOD(dismiss)
|
|||
}
|
||||
|
||||
- (void)reloadFromRedBoxWindow:(__unused RCTRedBoxWindow *)redBoxWindow {
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:RCTReloadNotification object:nil userInfo:nil];
|
||||
[_bridge requestReload];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -363,8 +363,7 @@ void RCTProfileUnhookModules(RCTBridge *bridge)
|
|||
|
||||
+ (void)reload
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:RCTReloadNotification
|
||||
object:NULL];
|
||||
[RCTProfilingBridge() requestReload];
|
||||
}
|
||||
|
||||
+ (void)toggle:(UIButton *)target
|
||||
|
|
Loading…
Reference in New Issue