diff --git a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm index 1a93e7d409bc41..73948d77e78190 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm +++ b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm @@ -55,7 +55,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( if (self.newArchEnabled || self.fabricEnabled) { [RCTComponentViewFactory currentComponentViewFactory].thirdPartyFabricComponentsProvider = self; } - [self customizeRootView:(RCTRootView *)rootView]; self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; UIViewController *rootViewController = [self createRootViewController]; @@ -253,6 +252,10 @@ - (RCTRootViewFactory *)createRCTRootViewFactory return [weakSelf createBridgeWithDelegate:delegate launchOptions:launchOptions]; }; + configuration.customizeRootView = ^(UIView * _Nonnull rootView) { + return [weakSelf customizeRootView:(RCTRootView *)rootView]; + }; + configuration.sourceURLForBridge = ^NSURL *_Nullable(RCTBridge *_Nonnull bridge) { return [weakSelf sourceURLForBridge:bridge]; diff --git a/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.h b/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.h index 6c60403ea297c7..ebec3f45e46c44 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.h +++ b/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.h @@ -24,6 +24,7 @@ typedef UIView *_Nonnull ( ^RCTCreateRootViewWithBridgeBlock)(RCTBridge *bridge, NSString *moduleName, NSDictionary *initProps); typedef RCTBridge *_Nonnull ( ^RCTCreateBridgeWithDelegateBlock)(id delegate, NSDictionary *launchOptions); +typedef void (^RCTCustomizeRootViewBlock)(UIView *rootView); typedef NSURL *_Nullable (^RCTSourceURLForBridgeBlock)(RCTBridge *bridge); typedef NSURL *_Nullable (^RCTBundleURLBlock)(void); typedef NSArray> *_Nonnull (^RCTExtraModulesForBridgeBlock)(RCTBridge *bridge); @@ -99,6 +100,13 @@ typedef void (^RCTHostDidReceiveJSErrorStackBlock)( */ @property (nonatomic, nullable) RCTCreateBridgeWithDelegateBlock createBridgeWithDelegate; +/** + * Block that allows to customize the rootView that is passed to React Native. + * + * @parameter: rootView - The root view to customize. + */ +@property (nonatomic, nullable) RCTCustomizeRootViewBlock customizeRootView; + #pragma mark - RCTBridgeDelegate blocks /** diff --git a/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm b/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm index 2ae542f450cd20..377e5efeae8030 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm +++ b/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm @@ -150,17 +150,25 @@ - (UIView *)viewWithModuleName:(NSString *)moduleName sizeMeasureMode:RCTSurfaceSizeMeasureModeWidthExact | RCTSurfaceSizeMeasureModeHeightExact]; surfaceHostingProxyRootView.backgroundColor = [UIColor systemBackgroundColor]; + if (self->_configuration.customizeRootView != nil) { + self->_configuration.customizeRootView(surfaceHostingProxyRootView); + } return surfaceHostingProxyRootView; } [self createBridgeIfNeeded:launchOptions]; [self createBridgeAdapterIfNeeded]; + UIView *rootView; if (self->_configuration.createRootViewWithBridge != nil) { - return self->_configuration.createRootViewWithBridge(self.bridge, moduleName, initProps); + rootView = self->_configuration.createRootViewWithBridge(self.bridge, moduleName, initProps); + } else { + rootView = [self createRootViewWithBridge:self.bridge moduleName:moduleName initProps:initProps]; } - - return [self createRootViewWithBridge:self.bridge moduleName:moduleName initProps:initProps]; + if (self->_configuration.customizeRootView != nil) { + self->_configuration.customizeRootView(rootView); + } + return rootView; } - (RCTBridge *)createBridgeWithDelegate:(id)delegate launchOptions:(NSDictionary *)launchOptions