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 @@ -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];
Expand Down Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ typedef UIView *_Nonnull (
^RCTCreateRootViewWithBridgeBlock)(RCTBridge *bridge, NSString *moduleName, NSDictionary *initProps);
typedef RCTBridge *_Nonnull (
^RCTCreateBridgeWithDelegateBlock)(id<RCTBridgeDelegate> delegate, NSDictionary *launchOptions);
typedef void (^RCTCustomizeRootViewBlock)(UIView *rootView);
typedef NSURL *_Nullable (^RCTSourceURLForBridgeBlock)(RCTBridge *bridge);
typedef NSURL *_Nullable (^RCTBundleURLBlock)(void);
typedef NSArray<id<RCTBridgeModule>> *_Nonnull (^RCTExtraModulesForBridgeBlock)(RCTBridge *bridge);
Expand Down Expand Up @@ -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

/**
Expand Down
14 changes: 11 additions & 3 deletions packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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<RCTBridgeDelegate>)delegate launchOptions:(NSDictionary *)launchOptions
Expand Down