From 33e0521788484eaba20beeeaabba2496854583a7 Mon Sep 17 00:00:00 2001 From: Mathieu Acthernoene Date: Wed, 10 May 2023 05:48:17 -0700 Subject: [PATCH] Add view getter on RCTRootView / RCTFabricSurfaceHostingProxyRootView (#37310) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Hi 👋 During the [react-native-bootsplash](https://github.com/zoontek/react-native-bootsplash) implementation of the new architecture, I noticed a few thing regarding `RCTRootView` / `RCTFabricSurfaceHostingProxyRootView` compat. Currently `RCTRootView` inherits from `UIView`, but `RCTFabricSurfaceHostingProxyRootView` does not, which this works: ```obj-c - (UIView *)createRootViewWithBridge:(RCTBridge *)bridge moduleName:(NSString *)moduleName initProps:(NSDictionary *)initProps { RCTRootView *rootView = (RCTRootView *) [super createRootViewWithBridge:bridge moduleName:moduleName initProps:initProps]; UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"LaunchScreen" bundle:nil]; UIView *loadingView = [[storyboard instantiateInitialViewController] view]; loadingView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; loadingView.frame = rootView.bounds; loadingView.center = (CGPoint){CGRectGetMidX(rootView.bounds), CGRectGetMidY(rootView.bounds)}; loadingView.hidden = NO; [rootView addSubview:loadingView]; return rootView; } ``` But this doesn't: ```obj-c - (UIView *)createRootViewWithBridge:(RCTBridge *)bridge moduleName:(NSString *)moduleName initProps:(NSDictionary *)initProps { RCTFabricSurfaceHostingProxyRootView *rootView = (RCTFabricSurfaceHostingProxyRootView *) [super createRootViewWithBridge:bridge moduleName:moduleName initProps:initProps]; UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"LaunchScreen" bundle:nil]; UIView *loadingView = [[storyboard instantiateInitialViewController] view]; loadingView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; loadingView.frame = rootView.bounds; loadingView.center = (CGPoint){CGRectGetMidX(rootView.bounds), CGRectGetMidY(rootView.bounds)}; loadingView.hidden = NO; [rootView addSubview:loadingView]; return rootView; } ``` Because `RCTFabricSurfaceHostingProxyRootView` is an imperfect proxy as it doesn't give access to the underlaying `UIView *`. As a solution, I added a prop on both: `UIView *view` PS: I'm well aware that `setLoadingView` also exists in both files, but it's currently not usable as the current `isActivityIndicatorViewVisible` / `isSurfaceViewVisible` / `_activityIndicatorViewFactory` logic in `RCTSurfaceHostingView.mm` doesn't work: a situation where `isActivityIndicatorViewVisible == true && isSurfaceViewVisible == false && _activityIndicatorViewFactory != nil` never happen: Screenshot_2023-05-06_at_18 10 18 ## Changelog: