Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions packages/react-native/Libraries/AppDelegate/RCTAppSetupUtils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,6 @@ void RCTAppSetupPrepareApp(UIApplication *application, BOOL turboModuleEnabled)
// Necessary to allow NativeModules to lookup TurboModules
[bridge setRCTTurboModuleRegistry:turboModuleManager];

#if RCT_DEV
/**
* Instantiating DevMenu has the side-effect of registering
* shortcuts for CMD + d, CMD + i, and CMD + n via RCTDevMenu.
* Therefore, when TurboModules are enabled, we must manually create this
* NativeModule.
*/
[turboModuleManager moduleForName:"RCTDevMenu"];
#endif // end RCT_DEV

Comment on lines -123 to -136
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this is inside RCT_REMOVE_LEGACY_ARCH, I guess this code is technically frozen?

auto runtimeInstallerLambda = [turboModuleManager, bridge, runtimeScheduler](facebook::jsi::Runtime &runtime) {
if (!bridge || !turboModuleManager) {
return;
Expand Down
20 changes: 20 additions & 0 deletions packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
#import <react/runtime/JSRuntimeFactory.h>
#import <react/runtime/JSRuntimeFactoryCAPI.h>

#if RCT_DEV_MENU
#import "RCTDevMenu.h"
#endif // RCT_DEV_MENU

@implementation RCTRootViewFactoryConfiguration

- (instancetype)initWithBundleURL:(NSURL *)bundleURL newArchEnabled:(BOOL)newArchEnabled
Expand Down Expand Up @@ -189,6 +193,12 @@ - (UIView *)viewWithModuleName:(NSString *)moduleName

RCTSurfaceHostingProxyRootView *surfaceHostingProxyRootView =
[[RCTSurfaceHostingProxyRootView alloc] initWithSurface:surface];
#if RCT_DEV_MENU
RCTDevMenu *devMenu = [self.reactHost.moduleRegistry moduleForClass:[RCTDevMenu class]];
if (devMenu) {
surfaceHostingProxyRootView.devMenu = devMenu;
}
#endif // RCT_DEV_MENU

surfaceHostingProxyRootView.backgroundColor = [UIColor systemBackgroundColor];
if (_configuration.customizeRootView != nil) {
Expand All @@ -208,6 +218,16 @@ - (UIView *)createRootViewWithBridge:(RCTBridge *)bridge
{
UIView *rootView = RCTAppSetupDefaultRootView(bridge, moduleName, initProps, YES);
rootView.backgroundColor = [UIColor systemBackgroundColor];

#if RCT_DEV_MENU
if ([rootView isKindOfClass:[RCTSurfaceHostingView class]]) {
RCTDevMenu *devMenu = [bridge moduleForClass:[RCTDevMenu class]];
if (devMenu) {
[(RCTSurfaceHostingView *)rootView setDevMenu:devMenu];
}
}
Comment on lines +223 to +228
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not entirely a fan of the class check here..

#endif // RCT_DEV_MENU

return rootView;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

@class RCTBridge;
@class RCTSurface;
@class RCTDevMenu;

typedef UIView *_Nullable (^RCTSurfaceHostingViewActivityIndicatorViewFactory)(void);

Expand Down Expand Up @@ -63,6 +64,14 @@ NS_ASSUME_NONNULL_BEGIN
* @param disabled if `YES`, the auto-hide is disabled. Otherwise the loading view will be hidden automatically
*/
- (void)disableActivityIndicatorAutoHide:(BOOL)disabled;

#if RCT_DEV_MENU
/**
* Dev menu for macOS context menu access.
*/
@property (nonatomic, strong, nullable) RCTDevMenu *devMenu;
#endif

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#import "RCTSurfaceView.h"
#import "RCTUtils.h"

#if RCT_DEV_MENU
#import "RCTDevMenu.h"
#endif // RCT_DEV_MENU

@interface RCTSurfaceHostingView ()

@property (nonatomic, assign) BOOL isActivityIndicatorViewVisible;
Expand Down Expand Up @@ -126,6 +130,7 @@ - (void)setSizeMeasureMode:(RCTSurfaceSizeMeasureMode)sizeMeasureMode
_sizeMeasureMode = sizeMeasureMode;
[self _invalidateLayout];
}

- (void)disableActivityIndicatorAutoHide:(BOOL)disabled
{
_autoHideDisabled = disabled;
Expand Down Expand Up @@ -249,4 +254,35 @@ - (void)surface:(__unused RCTSurface *)surface didChangeIntrinsicSize:(__unused
});
}

#pragma mark - Dev Menu

#if RCT_DEV_MENU
- (BOOL)canBecomeFirstResponder
{
return YES;
}

- (NSArray<UIKeyCommand *> *)keyCommands
{
// return [_devMenu keyCommands] ?: @[];

return @[
[UIKeyCommand keyCommandWithInput:@"d"
modifierFlags:UIKeyModifierCommand
action:@selector(toggle)],
[UIKeyCommand keyCommandWithInput:@"i"
modifierFlags:UIKeyModifierCommand
action:@selector(toggleElementInspector)],
];
}

- (void)toggle {
[_devMenu toggle];
}

- (void)toggleElementInspector {
[_devMenu toggleElementInspector];
}
#endif // RCT_DEV_MENU

@end
22 changes: 21 additions & 1 deletion packages/react-native/React/CoreModules/RCTDevMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ RCT_EXTERN NSString *const RCTShowDevMenuNotification;
/**
* Whether the hotkeys that toggles the developer menu is enabled.
*/
@property (nonatomic, assign) BOOL hotkeysEnabled;
@property (nonatomic, assign) BOOL hotkeysEnabled DEPRECATED_ATTRIBUTE;

/**
* Whether the developer menu is enabled.
Expand All @@ -84,6 +84,11 @@ RCT_EXTERN NSString *const RCTShowDevMenuNotification;
*/
- (void)show;

/**
* Manually toggle the dev menu
*/
- (void)toggle;

/**
* Deprecated, use `RCTReloadCommand` instead.
*/
Expand All @@ -105,6 +110,21 @@ RCT_EXTERN NSString *const RCTShowDevMenuNotification;
*/
- (void)disableReloadCommand;

/**
* Get the key commands for the dev menu (Cmd+D, Cmd+I, Cmd+R).
*/
- (NSArray<UIKeyCommand *> *)keyCommands;

/**
* Toggle the element inspector (called by key command).
*/
- (void)toggleElementInspector;

/**
* Reload from key command (called by key command).
*/
- (void)reloadFromKeyCommand;

@end

typedef NSString * (^RCTDevMenuItemTitleBlock)(void);
Expand Down
65 changes: 8 additions & 57 deletions packages/react-native/React/CoreModules/RCTDevMenu.mm
Original file line number Diff line number Diff line change
Expand Up @@ -150,56 +150,10 @@ - (instancetype)init

_keyboardShortcutsEnabled = true;
_devMenuEnabled = true;
[self registerHotkeys];
}
return self;
}

- (void)registerHotkeys
{
#if TARGET_OS_SIMULATOR || TARGET_OS_MACCATALYST
RCTKeyCommands *commands = [RCTKeyCommands sharedInstance];
__weak __typeof(self) weakSelf = self;

// Toggle debug menu
[commands registerKeyCommandWithInput:@"d"
modifierFlags:UIKeyModifierCommand
action:^(__unused UIKeyCommand *command) {
[weakSelf toggle];
}];

// Toggle element inspector
[commands registerKeyCommandWithInput:@"i"
modifierFlags:UIKeyModifierCommand
action:^(__unused UIKeyCommand *command) {
[(RCTDevSettings *)[weakSelf.moduleRegistry moduleForName:"DevSettings"]
toggleElementInspector];
}];
#endif
}

- (void)unregisterHotkeys
{
#if TARGET_OS_SIMULATOR || TARGET_OS_MACCATALYST
RCTKeyCommands *commands = [RCTKeyCommands sharedInstance];

[commands unregisterKeyCommandWithInput:@"d" modifierFlags:UIKeyModifierCommand];
[commands unregisterKeyCommandWithInput:@"i" modifierFlags:UIKeyModifierCommand];
#endif
}

- (BOOL)isHotkeysRegistered
{
#if TARGET_OS_SIMULATOR || TARGET_OS_MACCATALYST
RCTKeyCommands *commands = [RCTKeyCommands sharedInstance];

return [commands isKeyCommandRegisteredForInput:@"d" modifierFlags:UIKeyModifierCommand] &&
[commands isKeyCommandRegisteredForInput:@"i" modifierFlags:UIKeyModifierCommand];
#else
return NO;
#endif
}

- (BOOL)isReloadCommandRegistered
{
#if TARGET_OS_SIMULATOR || TARGET_OS_MACCATALYST
Expand Down Expand Up @@ -523,25 +477,22 @@ - (BOOL)hotLoadingEnabled
return ((RCTDevSettings *)[_moduleRegistry moduleForName:"DevSettings"]).isHotLoadingEnabled;
}

- (void)setHotkeysEnabled:(BOOL)enabled
- (void)disableReloadCommand
{
if (enabled) {
[self registerHotkeys];
} else {
[self unregisterHotkeys];
if ([self isReloadCommandRegistered]) {
[self unregisterReloadCommand];
}
}

- (BOOL)hotkeysEnabled
- (void)toggleElementInspector
{
return [self isHotkeysRegistered];
RCTDevSettings *devSettings = [_moduleRegistry moduleForName:"DevSettings"];
[devSettings toggleElementInspector];
}

- (void)disableReloadCommand
- (void)reloadFromKeyCommand
{
if ([self isReloadCommandRegistered]) {
[self unregisterReloadCommand];
}
RCTTriggerReloadCommandListeners(@"Dev menu key command");
}

- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,16 +358,6 @@ - (void)_start
jsInvoker:jsCallInvoker
devMenuConfigurationDecorator:_devMenuConfigurationDecorator];

#if RCT_DEV
/**
* Instantiating DevMenu has the side-effect of registering
* shortcuts for CMD + d, CMD + i, and CMD + n via RCTDevMenu.
* Therefore, when TurboModules are enabled, we must manually create this
* NativeModule.
*/
[_turboModuleManager moduleForName:"RCTDevMenu"];
#endif // end RCT_DEV

// Initialize RCTModuleRegistry so that TurboModules can require other TurboModules.
[_bridgeModuleDecorator.moduleRegistry setTurboModuleRegistry:_turboModuleManager];

Expand Down
Loading