From 31cf4c4eada59bde62f30e14024719779fc23a91 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Tue, 24 Oct 2023 04:26:48 -0700 Subject: [PATCH] Fix AppDelegate not passing props in bridgeless and rename getBundleURL (#41169) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/41169 * `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 fbshipit-source-id: b718ebf2590b1d4512bcbd4846c8d11200f486e4 --- .../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 c4ee6066af2..c92ca300e35 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 43d4b0bd4b0..39f76375ab7 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm +++ b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm @@ -88,7 +88,6 @@ static NSString *const kRNConcurrentRoot = @"concurrentRoot"; 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 @@ static NSString *const kRNConcurrentRoot = @"concurrentRoot"; [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 @@ static NSString *const kRNConcurrentRoot = @"concurrentRoot"; - (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 @@ static NSString *const kRNConcurrentRoot = @"concurrentRoot"; contextContainer->insert("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 40582e7296b..16a33fa3cab 100644 --- a/packages/rn-tester/RNTester/AppDelegate.mm +++ b/packages/rn-tester/RNTester/AppDelegate.mm @@ -127,7 +127,7 @@ NSString *kBundlePath = @"js/RNTesterApp.ios"; } #endif -- (NSURL *)getBundleURL +- (NSURL *)bundleURL { return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:kBundlePath]; }