mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
2a13f12106
Summary: This diff adds back RN reload reason, which was removed earlier in the stack. cc/Rick For callsites which already had a reason, I kept the string exactly the same. For callsites which didn't have a reason, I made up something reasonable. Changelog: [Internal][Fixed] Re-implemented bridge reload reason text. Reviewed By: RSNara Differential Revision: D18074478 fbshipit-source-id: 64a3cd7718674a7ba7228a80e34791ce9f153f9f
51 lines
1.8 KiB
Objective-C
51 lines
1.8 KiB
Objective-C
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#import "RCTReloadCommand.h"
|
|
|
|
#import "RCTAssert.h"
|
|
#import "RCTKeyCommands.h"
|
|
#import "RCTUtils.h"
|
|
|
|
/** main queue only */
|
|
static NSHashTable<id<RCTReloadListener>> *listeners;
|
|
|
|
NSString *const RCTTriggerReloadCommandNotification = @"RCTTriggerReloadCommandNotification";
|
|
NSString *const RCTTriggerReloadCommandReasonKey = @"reason";
|
|
|
|
void RCTRegisterReloadCommandListener(id<RCTReloadListener> listener)
|
|
{
|
|
RCTAssertMainQueue(); // because registerKeyCommandWithInput: must be called on the main thread
|
|
static dispatch_once_t onceToken;
|
|
dispatch_once(&onceToken, ^{
|
|
listeners = [NSHashTable weakObjectsHashTable];
|
|
[[RCTKeyCommands sharedInstance] registerKeyCommandWithInput:@"r"
|
|
modifierFlags:UIKeyModifierCommand
|
|
action:
|
|
^(__unused UIKeyCommand *command) {
|
|
RCTTriggerReloadCommandListeners(@"Command + R");
|
|
}];
|
|
});
|
|
[listeners addObject:listener];
|
|
}
|
|
|
|
void RCTTriggerReloadCommandListeners(NSString *reason)
|
|
{
|
|
RCTAssertMainQueue();
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:RCTTriggerReloadCommandNotification
|
|
object:nil
|
|
userInfo:@{RCTTriggerReloadCommandReasonKey: RCTNullIfNil(reason)} ];
|
|
|
|
// Copy to protect against mutation-during-enumeration.
|
|
// If listeners hasn't been initialized yet we get nil, which works just fine.
|
|
NSArray<id<RCTReloadListener>> *copiedListeners = [listeners allObjects];
|
|
for (id<RCTReloadListener> l in copiedListeners) {
|
|
[l didReceiveReloadCommand];
|
|
}
|
|
}
|