Skip to content

Commit

Permalink
Fix AppDelegate not passing props in bridgeless and rename getBundleU…
Browse files Browse the repository at this point in the history
…RL (#41169)

Summary:
Pull Request resolved: #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
  • Loading branch information
javache authored and facebook-github-bot committed Oct 24, 2023
1 parent 70acd3f commit 31cf4c4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
- (BOOL)bridgelessEnabled;

/// Return the bundle URL for the main bundle.
- (NSURL *)getBundleURL;
- (NSURL *)bundleURL;

#endif

Expand Down
13 changes: 6 additions & 7 deletions packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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<facebook::react::JSEngineInstance>() {
return [weakSelf createJSEngineInstance];
}];
[_reactHost setBundleURLProvider:^NSURL *() {
return [weakSelf getBundleURL];
return [weakSelf bundleURL];
}];
[_reactHost setContextContainerHandler:self];
[_reactHost start];
Expand All @@ -311,9 +310,9 @@ - (void)didCreateContextContainer:(std::shared_ptr<facebook::react::ContextConta
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;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/rn-tester/RNTester/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ - (void)application:(__unused UIApplication *)application
}
#endif

- (NSURL *)getBundleURL
- (NSURL *)bundleURL
{
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:kBundlePath];
}
Expand Down

0 comments on commit 31cf4c4

Please sign in to comment.