From 1ccc7a3e9eec0dccfa4ccbedc8c19281f0355377 Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Wed, 28 Feb 2024 06:09:38 -0800 Subject: [PATCH] Deprecate `getSurfacePresenter` and `getModuleRegistry` in favor of their props Summary: This change align the `getSurfacePresenter` and `getModuleRegistry` to the iOS convention for which these should be computed properties with no `get` prefix in their name. We want to land this change and to pick it in 0.74 so we can remove the `get` versions in 0.75. ## Changelog: [iOS][Deprecated] - Deprecate `getSurfacePresenter` and `getModuleRegistry` for `surfacePresenter` and moduleRegistry` props. Reviewed By: javache Differential Revision: D54253805 fbshipit-source-id: e9ff7db744a73a3bd0f8ae1d87875e54ddd9a1a4 --- .../platform/ios/ReactCommon/RCTHost.h | 8 ++++++-- .../platform/ios/ReactCommon/RCTHost.mm | 20 +++++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTHost.h b/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTHost.h index 6b869377a83..ea4492980f9 100644 --- a/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTHost.h +++ b/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTHost.h @@ -52,6 +52,10 @@ typedef std::shared_ptr (^RCTHostJSEngineProv @property (nonatomic, weak, nullable) id runtimeDelegate; +@property (nonatomic, readonly) RCTSurfacePresenter *surfacePresenter; + +@property (nonatomic, readonly) RCTModuleRegistry *moduleRegistry; + - (void)start; - (void)callFunctionOnJSModule:(NSString *)moduleName method:(NSString *)method args:(NSArray *)args; @@ -64,11 +68,11 @@ typedef std::shared_ptr (^RCTHostJSEngineProv - (RCTFabricSurface *)createSurfaceWithModuleName:(NSString *)moduleName initialProperties:(NSDictionary *)properties; -- (RCTSurfacePresenter *)getSurfacePresenter; +- (RCTSurfacePresenter *)getSurfacePresenter __attribute__((deprecated("Use `surfacePresenter` property instead."))); // Native module API -- (RCTModuleRegistry *)getModuleRegistry; +- (RCTModuleRegistry *)getModuleRegistry __attribute__((deprecated("Use `moduleRegistry` property instead."))); @end diff --git a/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTHost.mm b/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTHost.mm index 85602c4c8a6..ff0bb9703d3 100644 --- a/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTHost.mm +++ b/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTHost.mm @@ -212,7 +212,7 @@ class RCTHostPageTargetDelegate : public facebook::react::jsinspector_modern::Pa mode:(DisplayMode)displayMode initialProperties:(NSDictionary *)properties { - RCTFabricSurface *surface = [[RCTFabricSurface alloc] initWithSurfacePresenter:[self getSurfacePresenter] + RCTFabricSurface *surface = [[RCTFabricSurface alloc] initWithSurfacePresenter:self.surfacePresenter moduleName:moduleName initialProperties:properties]; surface.surfaceHandler.setDisplayMode(displayMode); @@ -235,16 +235,28 @@ class RCTHostPageTargetDelegate : public facebook::react::jsinspector_modern::Pa return [self createSurfaceWithModuleName:moduleName mode:DisplayMode::Visible initialProperties:properties]; } -- (RCTModuleRegistry *)getModuleRegistry +- (RCTModuleRegistry *)moduleRegistry { return _moduleRegistry; } -- (RCTSurfacePresenter *)getSurfacePresenter +// Deprecated +- (RCTModuleRegistry *)getModuleRegistry +{ + return self.moduleRegistry; +} + +- (RCTSurfacePresenter *)surfacePresenter { return [_instance surfacePresenter]; } +// Deprecated +- (RCTSurfacePresenter *)getSurfacePresenter +{ + return self.surfacePresenter; +} + - (void)callFunctionOnJSModule:(NSString *)moduleName method:(NSString *)method args:(NSArray *)args { [_instance callFunctionOnJSModule:moduleName method:method args:args]; @@ -276,7 +288,7 @@ class RCTHostPageTargetDelegate : public facebook::react::jsinspector_modern::Pa [_hostDelegate hostDidStart:self]; for (RCTFabricSurface *surface in [self _getAttachedSurfaces]) { - [surface resetWithSurfacePresenter:[self getSurfacePresenter]]; + [surface resetWithSurfacePresenter:self.surfacePresenter]; } }