Migrate bridge reload to RCTReloadCommand [2/n]

Summary:
Motivation described in diff 1/N.

This diff replaces calls to `[bridge reload]` with calls to `RCTReloadCommand`. This shouldn't have any change in behaviour since RCTBridge listens to RCTReloadCommand and calls `[bridge reload]` [here](https://fburl.com/diffusion/kemzkrei).

It will allow us to customize who listens and reacts to RN lifecycle.

Changelog: [Internal][Changed] - Migrated [bridge reload] calls to RCTReloadCommand

Reviewed By: shergin

Differential Revision: D17880909

fbshipit-source-id: 80b26c6badd4b216656fed6dd04554e9877f4bb7
This commit is contained in:
Peter Argany
2019-10-30 12:23:24 -07:00
committed by Facebook Github Bot
parent ffe2306164
commit d98cd7d3a1
8 changed files with 19 additions and 17 deletions
-2
View File
@@ -354,11 +354,9 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
Class bridgeClass = self.bridgeClass;
#if RCT_DEV
RCTExecuteOnMainQueue(^{
RCTRegisterReloadCommandListener(self);
});
#endif
// Only update bundleURL from delegate if delegate bundleURL has changed
NSURL *previousDelegateURL = _delegateBundleURL;
+1 -1
View File
@@ -24,6 +24,6 @@
RCT_EXTERN void RCTRegisterReloadCommandListener(id<RCTReloadListener> listener);
/**
* Triggers a reload for all current listeners.
* Triggers a reload for all current listeners. Replaces [_bridge reload].
*/
RCT_EXTERN void RCTTriggerReloadCommandListeners(void);
+2 -1
View File
@@ -12,6 +12,7 @@
#import <React/RCTDefines.h>
#import <React/RCTLog.h>
#import <React/RCTRedBox.h>
#import <React/RCTReloadCommand.h>
#import <React/RCTRootView.h>
#import "CoreModulesPlugins.h"
@@ -58,7 +59,7 @@ RCT_EXPORT_METHOD(reportFatalException:(NSString *)message
static NSUInteger reloadRetries = 0;
if (!RCT_DEBUG && reloadRetries < _maxReloadAttempts) {
reloadRetries++;
[_bridge reload];
RCTTriggerReloadCommandListeners();
} else {
NSString *description = [@"Unhandled JS Exception: " stringByAppendingString:message];
NSDictionary *errorInfo = @{ NSLocalizedDescriptionKey: description, RCTJSStackTraceKey: stack };
+3 -2
View File
@@ -24,6 +24,7 @@
#import <React/RCTPerformanceLogger.h>
#import <React/RCTProfile.h>
#import <React/RCTRedBox.h>
#import <React/RCTReloadCommand.h>
#import <React/RCTUtils.h>
#import <React/RCTFollyConvert.h>
#import <cxxreact/CxxNativeModule.h>
@@ -1009,7 +1010,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR
if (!_valid) {
RCTLogWarn(@"Attempting to reload bridge before it's valid: %@. Try restarting the development server if connected.", self);
}
[_parentBridge reloadWithReason:@"Unknown from cxx bridge"];
RCTTriggerReloadCommandListeners();
}
- (void)reloadWithReason:(NSString *)reason
@@ -1017,7 +1018,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR
if (!_valid) {
RCTLogWarn(@"Attempting to reload bridge before it's valid: %@. Try restarting the development server if connected.", self);
}
[_parentBridge reloadWithReason:reason];
RCTTriggerReloadCommandListeners();
}
- (Class)executorClass
+1 -1
View File
@@ -61,7 +61,7 @@ RCT_EXTERN NSString *const RCTShowDevMenuNotification;
- (void)show;
/**
* Deprecated, use -[RCTBRidge reload] instead.
* Deprecated, use `RCTReloadCommand` instead.
*/
- (void)reload DEPRECATED_ATTRIBUTE;
+5 -4
View File
@@ -13,6 +13,7 @@
#import <React/RCTDevSettings.h>
#import <React/RCTKeyCommands.h>
#import <React/RCTLog.h>
#import <React/RCTReloadCommand.h>
#import <React/RCTUtils.h>
#if RCT_DEV_MENU
@@ -200,7 +201,7 @@ RCT_EXPORT_MODULE()
[[RCTBundleURLProvider sharedSettings] resetToDefaults];
self->_bridge.bundleURL = [[RCTBundleURLProvider sharedSettings] jsBundleURLForFallbackResource:nil
fallbackExtension:nil];
[self->_bridge reloadWithReason:@"Dev menu - reset to default"];
RCTTriggerReloadCommandListeners();
}
- (NSArray<RCTDevMenuItem *> *)_menuItemsToPresent
@@ -214,7 +215,7 @@ RCT_EXPORT_MODULE()
[items addObject:[RCTDevMenuItem buttonItemWithTitle:@"Reload"
handler:^{
[bridge reloadWithReason:@"Dev menu - reload"];
RCTTriggerReloadCommandListeners();
}]];
if (!devSettings.isProfilingEnabled) {
@@ -373,7 +374,7 @@ RCT_EXPORT_MODULE()
fallbackResource:nil]
: [strongBridge.delegate sourceURLForBridge:strongBridge];
strongBridge.bundleURL = bundleURL;
[strongBridge reloadWithReason:@"Dev menu - apply changes"];
RCTTriggerReloadCommandListeners();
}
}]];
[alertController addAction:[UIAlertAction actionWithTitle:@"Reset to Default"
@@ -460,7 +461,7 @@ RCT_EXPORT_METHOD(show)
RCT_EXPORT_METHOD(reload)
{
WARN_DEPRECATED_DEV_MENU_EXPORT();
[_bridge reloadWithReason:@"Unknown from JS"];
RCTTriggerReloadCommandListeners();
}
RCT_EXPORT_METHOD(debugRemotely : (BOOL)enableDebug)
+5 -5
View File
@@ -14,6 +14,7 @@
#import "RCTEventDispatcher.h"
#import "RCTLog.h"
#import "RCTProfile.h"
#import "RCTReloadCommand.h"
#import "RCTUtils.h"
#import <React/RCTDevMenu.h>
@@ -171,7 +172,7 @@ RCT_EXPORT_MODULE()
if (params != (id)kCFNull && [params[@"debug"] boolValue]) {
weakBridge.executorClass = objc_lookUpClass("RCTWebSocketExecutor");
}
[weakBridge reloadWithReason:@"Global hotkey"];
RCTTriggerReloadCommandListeners();
}
queue:dispatch_get_main_queue()
forMethod:@"reload"];
@@ -246,13 +247,12 @@ RCT_EXPORT_MODULE()
RCT_EXPORT_METHOD(reload)
{
[self.bridge reloadWithReason:@"Unknown From JS"];
RCTTriggerReloadCommandListeners();
}
RCT_EXPORT_METHOD(reloadWithReason : (NSString *) reason)
{
[self.bridge reloadWithReason:reason];
RCTTriggerReloadCommandListeners();
}
RCT_EXPORT_METHOD(onFastRefresh)
@@ -390,7 +390,7 @@ RCT_EXPORT_METHOD(addMenuItem:(NSString *)title)
}
self.bridge.executorClass = executorClass;
[self.bridge reloadWithReason:@"Custom executor class reset"];
RCTTriggerReloadCommandListeners();
}
}
+2 -1
View File
@@ -14,6 +14,7 @@
#import "RCTEventDispatcher.h"
#import "RCTJSStackFrame.h"
#import "RCTRedBoxExtraDataViewController.h"
#import "RCTReloadCommand.h"
#import "RCTUtils.h"
#import <objc/runtime.h>
@@ -646,7 +647,7 @@ RCT_EXPORT_METHOD(dismiss)
if (_overrideReloadAction) {
_overrideReloadAction();
} else {
[_bridge reloadWithReason:@"Redbox"];
RCTTriggerReloadCommandListeners();
}
[self dismiss];
}