From 76ba5aedfb82fed04e3a8dda914ceba66fb7f33d Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Tue, 24 Oct 2023 03:45:35 -0700 Subject: [PATCH] Fix AppDelegate not passing props in bridgeless and rename getBundleURL (#41169) Summary: * `initialProperties` should be based on `prepareInitialProps`, not `launchOptions` (which don't seem to have an equivalent in bridgeless) * `getBundleURL` is not idiomatic Objective-C (eg https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/NamingMethods.html), so rename to `bundleURL` Changelog: [Internal] Reviewed By: cipolleschi Differential Revision: D50595790 --- .../Libraries/AppDelegate/RCTAppDelegate.h | 2 +- .../Libraries/AppDelegate/RCTAppDelegate.mm | 13 ++++++------- packages/rn-tester/RNTester/AppDelegate.mm | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h index c4ee6066af2bc6..c92ca300e35e3c 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h +++ b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h @@ -139,7 +139,7 @@ - (BOOL)bridgelessEnabled; /// Return the bundle URL for the main bundle. -- (NSURL *)getBundleURL; +- (NSURL *)bundleURL; #endif diff --git a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm index 43d4b0bd4b06c6..39f76375ab79e2 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm +++ b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm @@ -88,7 +88,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( RCTAppSetupPrepareApp(application, enableTM); UIView *rootView; - if (enableBridgeless) { #if RCT_NEW_ARCH_ENABLED // Enable native view config interop only if both bridgeless mode and Fabric is enabled. @@ -101,8 +100,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( [self createReactHost]; [self unstable_registerLegacyComponents]; [RCTComponentViewFactory currentComponentViewFactory].thirdPartyFabricComponentsProvider = self; - RCTFabricSurface *surface = [_reactHost createSurfaceWithModuleName:self.moduleName - initialProperties:launchOptions]; + NSDictionary *initProps = [self prepareInitialProps]; + RCTFabricSurface *surface = [_reactHost createSurfaceWithModuleName:self.moduleName initialProperties:initProps]; RCTSurfaceHostingProxyRootView *surfaceHostingProxyRootView = [[RCTSurfaceHostingProxyRootView alloc] initWithSurface:surface @@ -284,14 +283,14 @@ - (void)unstable_registerLegacyComponents - (void)createReactHost { __weak __typeof(self) weakSelf = self; - _reactHost = [[RCTHost alloc] initWithBundleURL:[self getBundleURL] + _reactHost = [[RCTHost alloc] initWithBundleURL:[self bundleURL] hostDelegate:nil turboModuleManagerDelegate:self jsEngineProvider:^std::shared_ptr() { return [weakSelf createJSEngineInstance]; }]; [_reactHost setBundleURLProvider:^NSURL *() { - return [weakSelf getBundleURL]; + return [weakSelf bundleURL]; }]; [_reactHost setContextContainerHandler:self]; [_reactHost start]; @@ -311,9 +310,9 @@ - (void)didCreateContextContainer:(std::shared_ptrinsert("ReactNativeConfig", _reactNativeConfig); } -- (NSURL *)getBundleURL +- (NSURL *)bundleURL { - [NSException raise:@"RCTAppDelegate::getBundleURL not implemented" + [NSException raise:@"RCTAppDelegate::bundleURL not implemented" format:@"Subclasses must implement a valid getBundleURL method"]; return nullptr; } diff --git a/packages/rn-tester/RNTester/AppDelegate.mm b/packages/rn-tester/RNTester/AppDelegate.mm index 40582e7296bb95..16a33fa3cab524 100644 --- a/packages/rn-tester/RNTester/AppDelegate.mm +++ b/packages/rn-tester/RNTester/AppDelegate.mm @@ -127,7 +127,7 @@ - (void)application:(__unused UIApplication *)application } #endif -- (NSURL *)getBundleURL +- (NSURL *)bundleURL { return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:kBundlePath]; }