From 689dcf5382742282da478f142756f8d2967a2454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danilo=20B=C3=BCrger?= Date: Sat, 12 Mar 2022 08:32:09 -0800 Subject: [PATCH] Start surface after setting the delegate (#33402) Summary: When starting the surface, _propagateStageChange is called. This checks the delegate to call surface:didChangeStage: on it. When initWithSurface:sizeMeasureMode: is called after start, then the delegate will be nil and thus not be called. This turns it around so a delegate is present for the surface to propagate its state to. This fixes RCTContentDidAppearNotification not getting posted otherwise. ## Changelog [iOS] [Fixed] - Post RCTContentDidAppearNotification with new arch Pull Request resolved: https://github.com/facebook/react-native/pull/33402 Test Plan: I found it best to set a breakpoint in XCode to where RCTContentDidAppearNotification is being posted. Prior to the patch that breakpoint will not be called. After applying the patch, it will be called. Reviewed By: philIip Differential Revision: D34753329 Pulled By: ShikaSD fbshipit-source-id: cc44a4c3a787d49e22e9d0c3a82c0f11ed281a0a --- .../RCTSurfaceHostingProxyRootView.mm | 11 ++++------- .../SurfaceHostingView/RCTSurfaceHostingView.mm | 6 ++++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingProxyRootView.mm b/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingProxyRootView.mm index 626a47ed057ccf..8f48551167f398 100644 --- a/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingProxyRootView.mm +++ b/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingProxyRootView.mm @@ -73,13 +73,10 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge // `RCTRootViewSizeFlexibilityNone` is the RCTRootView's default. RCTSurfaceSizeMeasureMode sizeMeasureMode = convertToSurfaceSizeMeasureMode(RCTRootViewSizeFlexibilityNone); - id surface = [[self class] createSurfaceWithBridge:bridge - moduleName:moduleName - initialProperties:initialProperties]; - [surface start]; - if (self = [super initWithSurface:surface sizeMeasureMode:sizeMeasureMode]) { - // Nothing specific to do. - } + self = [super initWithBridge:bridge + moduleName:moduleName + initialProperties:initialProperties + sizeMeasureMode:sizeMeasureMode]; RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @""); diff --git a/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingView.mm b/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingView.mm index f271bb76957171..9dbfad6548dc65 100644 --- a/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingView.mm +++ b/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingView.mm @@ -46,8 +46,10 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge id surface = [[self class] createSurfaceWithBridge:bridge moduleName:moduleName initialProperties:initialProperties]; - [surface start]; - return [self initWithSurface:surface sizeMeasureMode:sizeMeasureMode]; + if (self = [self initWithSurface:surface sizeMeasureMode:sizeMeasureMode]) { + [surface start]; + } + return self; } - (instancetype)initWithSurface:(id)surface