From 1b6ee8fdd73dd984ddd6b227d2b65abfa0d8f9c5 Mon Sep 17 00:00:00 2001 From: Alex Hunt Date: Tue, 19 Dec 2023 15:18:05 -0800 Subject: [PATCH] Set InspectorFlags in RCTAppDelegate (#41976) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/41976 Progress towards an opt-in setup for our new CDP backend. - Wires up D51563107 to conditionally disable the legacy Hermes debugger via `ReactNativeConfig`. - **Configuration covered**: iOS, for the `RCTAppDelegate` code path. - Create C++-only overload of `RCTAppSetupPrepareApp`, deprecate the previous function. Changelog: [iOS][Deprecated] - Deprecate `RCTAppSetupPrepareApp`, replaced with C++ overload Reviewed By: motiz88 Differential Revision: D51589221 fbshipit-source-id: 1688f97c69abb06d271b4d26b875365a8d86ba77 --- .../Libraries/AppDelegate/RCTAppDelegate.mm | 2 +- .../Libraries/AppDelegate/RCTAppSetupUtils.h | 15 ++++++++++++++- .../Libraries/AppDelegate/RCTAppSetupUtils.mm | 17 +++++++++++++++++ .../AppDelegate/React-RCTAppDelegate.podspec | 1 + 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm index 3b29780304d69a..65c48ff28d2290 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm +++ b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm @@ -84,7 +84,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( NSDictionary *initProps = updateInitialProps([self prepareInitialProps], fabricEnabled); - RCTAppSetupPrepareApp(application, enableTM); + RCTAppSetupPrepareApp(application, enableTM, *_reactNativeConfig); UIView *rootView; if (enableBridgeless) { diff --git a/packages/react-native/Libraries/AppDelegate/RCTAppSetupUtils.h b/packages/react-native/Libraries/AppDelegate/RCTAppSetupUtils.h index d661fb4355c1c1..af14ba93b9178b 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTAppSetupUtils.h +++ b/packages/react-native/Libraries/AppDelegate/RCTAppSetupUtils.h @@ -11,6 +11,8 @@ #ifdef __cplusplus +#import + #import #ifndef RCT_USE_HERMES @@ -44,11 +46,22 @@ std::unique_ptr RCTAppSetupJsExecutorFactory RCTBridge *bridge, const std::shared_ptr &runtimeScheduler); +/** + * Register features and experiments prior to app initialization. + */ +void RCTAppSetupPrepareApp( + UIApplication *application, + BOOL turboModuleEnabled, + const facebook::react::ReactNativeConfig &reactNativeConfig); + #endif // __cplusplus RCT_EXTERN_C_BEGIN -void RCTAppSetupPrepareApp(UIApplication *application, BOOL turboModuleEnabled); +[[deprecated("Use the 3-argument overload of RCTAppSetupPrepareApp instead")]] void RCTAppSetupPrepareApp( + UIApplication *application, + BOOL turboModuleEnabled); + UIView *RCTAppSetupDefaultRootView( RCTBridge *bridge, NSString *moduleName, diff --git a/packages/react-native/Libraries/AppDelegate/RCTAppSetupUtils.mm b/packages/react-native/Libraries/AppDelegate/RCTAppSetupUtils.mm index 7e522f9742bb45..68b1f417995446 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTAppSetupUtils.mm +++ b/packages/react-native/Libraries/AppDelegate/RCTAppSetupUtils.mm @@ -24,6 +24,9 @@ #import #import +// jsinspector-modern +#import + void RCTAppSetupPrepareApp(UIApplication *application, BOOL turboModuleEnabled) { RCTEnableTurboModule(turboModuleEnabled); @@ -35,6 +38,20 @@ void RCTAppSetupPrepareApp(UIApplication *application, BOOL turboModuleEnabled) #endif } +void RCTAppSetupPrepareApp( + UIApplication *application, + BOOL turboModuleEnabled, + const facebook::react::ReactNativeConfig &reactNativeConfig) +{ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + RCTAppSetupPrepareApp(application, turboModuleEnabled); +#pragma clang diagnostic pop + + auto &inspectorFlags = facebook::react::jsinspector_modern::InspectorFlags::getInstance(); + inspectorFlags.initFromConfig(reactNativeConfig); +} + UIView * RCTAppSetupDefaultRootView(RCTBridge *bridge, NSString *moduleName, NSDictionary *initialProperties, BOOL fabricEnabled) { diff --git a/packages/react-native/Libraries/AppDelegate/React-RCTAppDelegate.podspec b/packages/react-native/Libraries/AppDelegate/React-RCTAppDelegate.podspec index f0ce494e422bc4..d115ef4e56b4a8 100644 --- a/packages/react-native/Libraries/AppDelegate/React-RCTAppDelegate.podspec +++ b/packages/react-native/Libraries/AppDelegate/React-RCTAppDelegate.podspec @@ -87,6 +87,7 @@ Pod::Spec.new do |s| add_dependency(s, "React-utils") add_dependency(s, "React-debug") add_dependency(s, "React-rendererdebug") + add_dependency(s, "React-jsinspector") if use_hermes s.dependency "React-hermes"