mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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:
committed by
Facebook Github Bot
parent
ffe2306164
commit
d98cd7d3a1
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 };
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -61,7 +61,7 @@ RCT_EXTERN NSString *const RCTShowDevMenuNotification;
|
||||
- (void)show;
|
||||
|
||||
/**
|
||||
* Deprecated, use -[RCTBRidge reload] instead.
|
||||
* Deprecated, use `RCTReloadCommand` instead.
|
||||
*/
|
||||
- (void)reload DEPRECATED_ATTRIBUTE;
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user