Skip to content

Commit

Permalink
feat: add initialProps property to RCTAppDelegate (#35848)
Browse files Browse the repository at this point in the history
Summary:
Hi there,

While upgrading to 0.71 we realised the RCTAppDelegate doesn't offer a way to set custom `initProps` that would depend on `launchOptions`.

This PR adds an `initialProps` property to the RCTAppDelegate. This would let us set this property based on `launchOptions` in our implementation of `didFinishLaunchingWithOptions` before calling `[super didFinishLaunchingWithOptions]`

Thanks !

## Changelog

[IOS] [ADDED] - Add `initialProps` property to `RCTAppDelegate`

Pull Request resolved: #35848

Reviewed By: rshest

Differential Revision: D42543027

Pulled By: cipolleschi

fbshipit-source-id: 55374914890445f8193c12a06a943b7796edb457
  • Loading branch information
jblarriviere authored and facebook-github-bot committed Jan 18, 2023
1 parent 473eb1d commit b314e6f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions Libraries/AppDelegate/RCTAppDelegate.h
Expand Up @@ -55,6 +55,7 @@
@property (nonatomic, strong) UIWindow *window;
@property (nonatomic, strong) RCTBridge *bridge;
@property (nonatomic, strong) NSString *moduleName;
@property (nonatomic, strong) NSDictionary *initialProps;

/**
* It creates a `RCTBridge` using a delegate and some launch options.
Expand Down
2 changes: 1 addition & 1 deletion Libraries/AppDelegate/RCTAppDelegate.mm
Expand Up @@ -84,7 +84,7 @@ - (BOOL)concurrentRootEnabled

- (NSDictionary *)prepareInitialProps
{
NSMutableDictionary *initProps = [NSMutableDictionary new];
NSMutableDictionary *initProps = self.initialProps ? [self.initialProps mutableCopy] : [NSMutableDictionary new];

#ifdef RCT_NEW_ARCH_ENABLED
initProps[kRNConcurrentRoot] = @([self concurrentRootEnabled]);
Expand Down
4 changes: 4 additions & 0 deletions template/ios/HelloWorld/AppDelegate.mm
Expand Up @@ -7,6 +7,10 @@ @implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.moduleName = @"HelloWorld";
// You can add your custom initial props in the dictionary below.
// They will be passed down to the ViewController used by React Native.
self.initialProps = @{};

return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

Expand Down

0 comments on commit b314e6f

Please sign in to comment.