Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
@class RCTBridge;
@protocol RCTComponentViewProtocol;
@class RCTSurfacePresenterBridgeAdapter;
@class RCTDevMenuConfiguration;

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -116,6 +117,8 @@ typedef NS_ENUM(NSInteger, RCTReleaseLevel) { Canary, Experimental, Stable };

@property (nonatomic, weak) id<RCTReactNativeFactoryDelegate> delegate;

@property (nonatomic, nullable) RCTDevMenuConfiguration *devMenuConfiguration;

@end

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

#import "RCTReactNativeFactory.h"
#import <React/RCTColorSpaceUtils.h>
#import <React/RCTDevMenu.h>
#import <React/RCTLog.h>
#import <React/RCTRootView.h>
#import <React/RCTSurfacePresenterBridgeAdapter.h>
Expand Down Expand Up @@ -82,7 +83,8 @@ - (void)startReactNativeWithModuleName:(NSString *)moduleName
{
UIView *rootView = [self.rootViewFactory viewWithModuleName:moduleName
initialProperties:initialProperties
launchOptions:launchOptions];
launchOptions:launchOptions
devMenuConfiguration:self.devMenuConfiguration];
UIViewController *rootViewController = [_delegate createRootViewController];
[_delegate setRootView:rootView toRootViewController:rootViewController];
window.rootViewController = rootViewController;
Expand Down
14 changes: 13 additions & 1 deletion packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
@class RCTHost;
@class RCTRootView;
@class RCTSurfacePresenterBridgeAdapter;
@class RCTDevMenuConfiguration;

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -201,7 +202,13 @@ typedef void (^RCTLoadSourceForBridgeBlock)(RCTBridge *bridge, RCTSourceLoadBloc
* @parameter: moduleName - the name of the app, used by Metro to resolve the module.
* @parameter: initialProperties - a set of initial properties.
* @parameter: launchOptions - a dictionary with a set of options.
* @parameter: devMenuConfiguration - a configuration for enabling/disabling dev menu.
*/
- (UIView *_Nonnull)viewWithModuleName:(NSString *)moduleName
initialProperties:(NSDictionary *__nullable)initialProperties
launchOptions:(NSDictionary *__nullable)launchOptions
devMenuConfiguration:(RCTDevMenuConfiguration *__nullable)devMenuConfiguration;

- (UIView *_Nonnull)viewWithModuleName:(NSString *)moduleName
initialProperties:(NSDictionary *__nullable)initialProperties
launchOptions:(NSDictionary *__nullable)launchOptions;
Expand All @@ -219,11 +226,16 @@ typedef void (^RCTLoadSourceForBridgeBlock)(RCTBridge *bridge, RCTSourceLoadBloc
* Use it to speed up later viewWithModuleName: calls.
*
* @parameter: launchOptions - a dictionary with a set of options.
* @parameter: devMenuConfiguration - a configuration for enabling/disabling dev menu.
*/
- (void)initializeReactHostWithLaunchOptions:(NSDictionary *__nullable)launchOptions;
- (void)initializeReactHostWithLaunchOptions:(NSDictionary *__nullable)launchOptions
devMenuConfiguration:(RCTDevMenuConfiguration *)devMenuConfiguration;

- (RCTHost *)createReactHost:(NSDictionary *__nullable)launchOptions;

- (RCTHost *)createReactHost:(NSDictionary *__nullable)launchOptions
devMenuConfiguration:(RCTDevMenuConfiguration *__nullable)devMenuConfiguration;

@end

NS_ASSUME_NONNULL_END
39 changes: 33 additions & 6 deletions packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#import "RCTRootViewFactory.h"
#import <React/RCTCxxBridgeDelegate.h>
#import <React/RCTDevMenu.h>
#import <React/RCTLog.h>
#import <React/RCTRootView.h>
#import <React/RCTSurfacePresenterBridgeAdapter.h>
Expand Down Expand Up @@ -133,29 +134,47 @@ - (instancetype)initWithConfiguration:(RCTRootViewFactoryConfiguration *)configu

- (UIView *)viewWithModuleName:(NSString *)moduleName initialProperties:(NSDictionary *)initialProperties
{
return [self viewWithModuleName:moduleName initialProperties:initialProperties launchOptions:nil];
return [self viewWithModuleName:moduleName
initialProperties:initialProperties
launchOptions:nil
devMenuConfiguration:[RCTDevMenuConfiguration defaultConfiguration]];
}

- (UIView *)viewWithModuleName:(NSString *)moduleName
{
return [self viewWithModuleName:moduleName initialProperties:nil launchOptions:nil];
return [self viewWithModuleName:moduleName
initialProperties:nil
launchOptions:nil
devMenuConfiguration:[RCTDevMenuConfiguration defaultConfiguration]];
}

- (void)initializeReactHostWithLaunchOptions:(NSDictionary *)launchOptions
devMenuConfiguration:(RCTDevMenuConfiguration *)devMenuConfiguration
{
// Enable TurboModule interop by default in Bridgeless mode
RCTEnableTurboModuleInterop(YES);
RCTEnableTurboModuleInteropBridgeProxy(YES);

[self createReactHostIfNeeded:launchOptions];
[self createReactHostIfNeeded:launchOptions devMenuConfiguration:devMenuConfiguration];
return;
}

- (UIView *)viewWithModuleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties
launchOptions:(NSDictionary *)launchOptions
{
return [self viewWithModuleName:moduleName
initialProperties:initialProperties
launchOptions:launchOptions
devMenuConfiguration:[RCTDevMenuConfiguration defaultConfiguration]];
}

- (UIView *)viewWithModuleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initProps
launchOptions:(NSDictionary *)launchOptions
devMenuConfiguration:(RCTDevMenuConfiguration *)devMenuConfiguration
{
[self initializeReactHostWithLaunchOptions:launchOptions];
[self initializeReactHostWithLaunchOptions:launchOptions devMenuConfiguration:devMenuConfiguration];

RCTFabricSurface *surface = [self.reactHost createSurfaceWithModuleName:moduleName
initialProperties:initProps ? initProps : @{}];
Expand Down Expand Up @@ -226,14 +245,21 @@ - (void)createBridgeAdapterIfNeeded
#pragma mark - New Arch Utilities

- (void)createReactHostIfNeeded:(NSDictionary *)launchOptions
devMenuConfiguration:(RCTDevMenuConfiguration *)devMenuConfiguration
{
if (self.reactHost) {
return;
}
self.reactHost = [self createReactHost:launchOptions];
self.reactHost = [self createReactHost:launchOptions devMenuConfiguration:devMenuConfiguration];
}

- (RCTHost *)createReactHost:(NSDictionary *)launchOptions
{
return [self createReactHost:launchOptions devMenuConfiguration:[RCTDevMenuConfiguration defaultConfiguration]];
}

- (RCTHost *)createReactHost:(NSDictionary *)launchOptions
devMenuConfiguration:(RCTDevMenuConfiguration *)devMenuConfiguration
{
__weak __typeof(self) weakSelf = self;
RCTHost *reactHost =
Expand All @@ -243,7 +269,8 @@ - (RCTHost *)createReactHost:(NSDictionary *)launchOptions
jsEngineProvider:^std::shared_ptr<facebook::react::JSRuntimeFactory>() {
return [weakSelf createJSRuntimeFactory];
}
launchOptions:launchOptions];
launchOptions:launchOptions
devMenuConfiguration:devMenuConfiguration];
[reactHost setBundleURLProvider:^NSURL *() {
return [weakSelf bundleURL];
}];
Expand Down
8 changes: 4 additions & 4 deletions packages/react-native/React/Base/RCTBundleURLProvider.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

const NSUInteger kRCTBundleURLProviderDefaultPort = RCT_METRO_PORT;

#if RCT_DEV_MENU | RCT_PACKAGER_LOADING_FUNCTIONALITY
#if RCT_DEV | RCT_PACKAGER_LOADING_FUNCTIONALITY
static BOOL kRCTAllowPackagerAccess = YES;
void RCTBundleURLProviderAllowPackagerServerAccess(BOOL allowed)
{
Expand Down Expand Up @@ -78,7 +78,7 @@ - (void)resetToDefaults
(unsigned long)kRCTBundleURLProviderDefaultPort]];
}

#if RCT_DEV_MENU | RCT_PACKAGER_LOADING_FUNCTIONALITY
#if RCT_DEV | RCT_PACKAGER_LOADING_FUNCTIONALITY
+ (BOOL)isPackagerRunning:(NSString *)hostPort
{
return [RCTBundleURLProvider isPackagerRunning:hostPort scheme:nil];
Expand Down Expand Up @@ -155,14 +155,14 @@ - (NSString *)packagerServerHost

- (NSString *)packagerServerHostPort
{
#if RCT_DEV_MENU | RCT_PACKAGER_LOADING_FUNCTIONALITY
#if RCT_DEV | RCT_PACKAGER_LOADING_FUNCTIONALITY
if (!kRCTAllowPackagerAccess) {
RCTLogInfo(@"Packager server access is disabled in this environment");
return nil;
}
#endif
NSString *location = [self jsLocation];
#if RCT_DEV_MENU
#if RCT_DEV
NSString *scheme = [self packagerScheme];
if ([location length] && ![RCTBundleURLProvider isPackagerRunning:location scheme:scheme]) {
location = nil;
Expand Down
31 changes: 30 additions & 1 deletion packages/react-native/React/CoreModules/RCTDevMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,26 @@
#import <React/RCTBridgeProxy.h>
#import <React/RCTDefines.h>

RCT_EXTERN NSString *const RCTShowDevMenuNotification;

@interface RCTDevMenuConfiguration : NSObject

#if RCT_DEV_MENU

RCT_EXTERN NSString *const RCTShowDevMenuNotification;
@property (nonatomic, readonly) BOOL devMenuEnabled;
@property (nonatomic, readonly) BOOL shakeGestureEnabled;
@property (nonatomic, readonly) BOOL keyboardShortcutsEnabled;

- (instancetype)initWithDevMenuEnabled:(BOOL)devMenuEnabled
shakeGestureEnabled:(BOOL)shakeGestureEnabled
keyboardShortcutsEnabled:(BOOL)keyboardShortcutsEnabled;

#endif

+ (instancetype)defaultConfiguration;

@end

@class RCTDevMenuItem;

/**
Expand Down Expand Up @@ -45,6 +59,16 @@ RCT_EXTERN NSString *const RCTShowDevMenuNotification;
*/
@property (nonatomic, assign) BOOL hotkeysEnabled;

/**
* Whether the developer menu is enabled.
*/
@property (nonatomic, assign) BOOL devMenuEnabled;

/**
* Whether keyboard shortcuts are enabled.
*/
@property (nonatomic, assign) BOOL keyboardShortcutsEnabled;

/**
* Presented items in development menu
*/
Expand Down Expand Up @@ -76,6 +100,11 @@ RCT_EXTERN NSString *const RCTShowDevMenuNotification;
*/
- (void)addItem:(RCTDevMenuItem *)item;

/**
* Disable the reload command (Cmd+R) in the simulator.
*/
- (void)disableReloadCommand;

@end

typedef NSString * (^RCTDevMenuItemTitleBlock)(void);
Expand Down
Loading
Loading