Skip to content

Commit

Permalink
feat: add initialProps property to RCTAppDelegate (facebook#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: facebook#35848

Reviewed By: rshest

Differential Revision: D42543027

Pulled By: cipolleschi

fbshipit-source-id: 55374914890445f8193c12a06a943b7796edb457
  • Loading branch information
jblarriviere authored and OlimpiaZurek committed May 22, 2023
1 parent 012c989 commit 3fdb106
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 3fdb106

Please sign in to comment.