From 13b93cfddaa559697968ac1c19e55f7aaa053070 Mon Sep 17 00:00:00 2001 From: Nolan O'Brien Date: Wed, 30 Oct 2024 21:08:32 -0700 Subject: [PATCH] Remove implicit "start", then clean up callsites (#47313) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/47313 We're going to fix up a bunch of designated initializers. `RCTSurfaceHostingProxyRootView` is particularly problematic because different initializers will do different things even though reading the code it looks like they should be equivalent. Remove the encapsulated "start" to the provided "surface", and require it to be explicit at the callsite. ## Changelog: [iOS][Changed] - `RCTSurfaceHostingProxyRootView` no longer has different behavior (whether it calls `start` on the provided *surface*) depending on which initializer is used. Call `start` yourself on the *surface* instead. Reviewed By: cipolleschi Differential Revision: D65214656 fbshipit-source-id: 179d5220d4f866b4452561e1bb6e2051020c8a11 --- .../react-native/Libraries/AppDelegate/RCTAppSetupUtils.mm | 4 +++- .../Libraries/AppDelegate/RCTRootViewFactory.mm | 5 ++--- .../SurfaceHostingView/RCTSurfaceHostingProxyRootView.mm | 7 ++----- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/react-native/Libraries/AppDelegate/RCTAppSetupUtils.mm b/packages/react-native/Libraries/AppDelegate/RCTAppSetupUtils.mm index d33fd071d89..0478efc6700 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTAppSetupUtils.mm +++ b/packages/react-native/Libraries/AppDelegate/RCTAppSetupUtils.mm @@ -53,7 +53,9 @@ RCTAppSetupDefaultRootView(RCTBridge *bridge, NSString *moduleName, NSDictionary id surface = [[RCTFabricSurface alloc] initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties]; - return [[RCTSurfaceHostingProxyRootView alloc] initWithSurface:surface]; + UIView *rootView = [[RCTSurfaceHostingProxyRootView alloc] initWithSurface:surface]; + [surface start]; + return rootView; } return [[RCTRootView alloc] initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties]; } diff --git a/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm b/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm index f5490705bed..4b687c5a3e0 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm +++ b/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm @@ -172,9 +172,8 @@ static NSDictionary *updateInitialProps(NSDictionary *initialProps, BOOL isFabri RCTFabricSurface *surface = [self.reactHost createSurfaceWithModuleName:moduleName initialProperties:initProps]; - RCTSurfaceHostingProxyRootView *surfaceHostingProxyRootView = [[RCTSurfaceHostingProxyRootView alloc] - initWithSurface:surface - sizeMeasureMode:RCTSurfaceSizeMeasureModeWidthExact | RCTSurfaceSizeMeasureModeHeightExact]; + RCTSurfaceHostingProxyRootView *surfaceHostingProxyRootView = + [[RCTSurfaceHostingProxyRootView alloc] initWithSurface:surface]; surfaceHostingProxyRootView.backgroundColor = [UIColor systemBackgroundColor]; if (self->_configuration.customizeRootView != nil) { diff --git a/packages/react-native/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingProxyRootView.mm b/packages/react-native/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingProxyRootView.mm index b14e74ea77e..e157d2fa2ac 100644 --- a/packages/react-native/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingProxyRootView.mm +++ b/packages/react-native/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingProxyRootView.mm @@ -53,11 +53,8 @@ static RCTRootViewSizeFlexibility convertToRootViewSizeFlexibility(RCTSurfaceSiz - (instancetype)initWithSurface:(id)surface { - if (self = [super initWithSurface:surface - sizeMeasureMode:RCTSurfaceSizeMeasureModeWidthExact | RCTSurfaceSizeMeasureModeHeightExact]) { - [surface start]; - } - return self; + return [super initWithSurface:surface + sizeMeasureMode:RCTSurfaceSizeMeasureModeWidthExact | RCTSurfaceSizeMeasureModeHeightExact]; } RCT_NOT_IMPLEMENTED(-(instancetype)initWithFrame : (CGRect)frame)