From a2708c876695a525523c97685cdf405b7ea75f3b Mon Sep 17 00:00:00 2001 From: Phillip Pan Date: Tue, 16 May 2023 17:36:32 -0700 Subject: [PATCH] replace host reload notifications with hostDidStart: (#37444) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/37444 Changelog: [Internal] In this change, I'm removing these public notification strings that are used to listen to CMD + R reload by replacing them with a more general, lifecycle callback. Consumers can use this if there's anything in userland that they need to do once React is ready, such as doing some work with any native modules. Reviewed By: sammy-SC Differential Revision: D45760847 fbshipit-source-id: 2601ce083df827f79ea3f888f13fff1fc53c9564 --- .../react/bridgeless/platform/ios/Core/RCTHost.h | 11 +---------- .../react/bridgeless/platform/ios/Core/RCTHost.mm | 9 ++------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHost.h b/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHost.h index ff2e088abf5..96fd88a7afd 100644 --- a/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHost.h +++ b/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHost.h @@ -25,16 +25,6 @@ NS_ASSUME_NONNULL_BEGIN FB_RUNTIME_PROTOCOL @protocol RCTTurboModuleManagerDelegate; -/** - * This notification fires just before RCTHost releases it's RCTInstance reference. - */ -RCT_EXTERN NSString *const RCTHostWillReloadNotification; - -/** - * This notification fires just after RCTHost releases it's RCTInstance reference. - */ -RCT_EXTERN NSString *const RCTHostDidReloadNotification; - typedef std::shared_ptr (^RCTHostJSEngineProvider)(void); @protocol RCTHostDelegate @@ -47,6 +37,7 @@ typedef std::shared_ptr (^RCTHostJSEngineProv message:(NSString *)message exceptionId:(NSUInteger)exceptionId isFatal:(BOOL)isFatal; +- (void)hostDidStart:(RCTHost *)host; @end diff --git a/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHost.mm b/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHost.mm index 2cb156f002d..7b86e035198 100644 --- a/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHost.mm +++ b/packages/react-native/ReactCommon/react/bridgeless/platform/ios/Core/RCTHost.mm @@ -20,9 +20,6 @@ using namespace facebook::react; -NSString *const RCTHostWillReloadNotification = @"RCTHostWillReloadNotification"; -NSString *const RCTHostDidReloadNotification = @"RCTHostDidReloadNotification"; - @interface RCTHost () @end @@ -156,6 +153,7 @@ NSString *const RCTHostDidReloadNotification = @"RCTHostDidReloadNotification"; onInitialBundleLoad:_onInitialBundleLoad bindingsInstallFunc:_bindingsInstallFunc moduleRegistry:_moduleRegistry]; + [_hostDelegate hostDidStart:self]; } - (RCTFabricSurface *)createSurfaceWithModuleName:(NSString *)moduleName @@ -204,8 +202,6 @@ NSString *const RCTHostDidReloadNotification = @"RCTHostDidReloadNotification"; - (void)didReceiveReloadCommand { - [[NSNotificationCenter defaultCenter] - postNotification:[NSNotification notificationWithName:RCTHostWillReloadNotification object:nil]]; [_instance invalidate]; _instance = nil; [self _refreshBundleURL]; @@ -224,8 +220,7 @@ NSString *const RCTHostDidReloadNotification = @"RCTHostDidReloadNotification"; onInitialBundleLoad:_onInitialBundleLoad bindingsInstallFunc:_bindingsInstallFunc moduleRegistry:_moduleRegistry]; - [[NSNotificationCenter defaultCenter] - postNotification:[NSNotification notificationWithName:RCTHostDidReloadNotification object:nil]]; + [_hostDelegate hostDidStart:self]; for (RCTFabricSurface *surface in [self _getAttachedSurfaces]) { [surface resetWithSurfacePresenter:[self getSurfacePresenter]];